Subject Re: Record versioning/timestamping
Author gregatacd
Actually, I'm more concerned about having the application check for
changes while I'm editing records. For example, in my application
user A will read a record from the database and have it presented
for viewing/editing. User A will then edit this data (over the
course of a few minutes). Meanwhile, User B (who had also pulled the
same record a bit earlier) updates the database with their changes.

So, when User A submits their changes, I want to know if the data
for that record has changed in the meantime, and deal with that in
some appropriate way. Thus the need for a timestamp/counter marker
to detect these changes; I can use this column to compare the
original value to the current value.

I suppose I could use a single generator for all records to populate
this column, but I could also simply increment the column in the
before update trigger... I just want to be sure that this will be a
fully atomic operation. This will also be more cross-DB platform
friendly (not many DBs have this fine generator feature), and will
give an audit as to how many times the record has been updated (it
may be useful information at some point...).

Greg



--- In firebird-support@yahoogroups.com, "Adam" <s3057043@y...>
wrote:
>
> Firstly, once you alter a record, it will not let another user
alter
> that record until you commit or rollback (its called a multiversion
> record), so it may not even be an issue for you. Depending on what
> transaction mode you use, their query will wait for your
transaction
> to commit/rollback or generate an exception.
>
> If you still want a record stamp, create a 64 bit integer column
and
> fill it using a generator. You may want to use a trigger to set
it, or
> you can return it to the calling program. Generators are thread
safe too.
>
> Adam
>
> --- In firebird-support@yahoogroups.com, "gregatacd"
<GregAtACD@h...>
> wrote:
> >
> > DB: Firebird 1.5
> >
> > I'm looking for a way to mark a record as being updated. For
> > example, I read a record with a timestamp or other mark, then
when I
> > update it (after the user enters some changes etc.), I find that
the
> > mark has changed somehow (another user updating the record
> > underneath me).
> >
> > What would be the best way to mark a record as updated or added?
> >
> > One potential solution would be to create a timestamp column and
> > have an update/insert trigger update the timestamp column each
time.
> > Is there a performance issue with this (since getting the
current
> > time may not be overly quick, and it must be done once per
> > update/insert).
> >
> > Or, add a 64bit integer column and have the triggers do a +1 on
this
> > column... would this be 'atomic' enough given that multiple
users
> > may be editing a given record...
> >
> > Any advice here on best practices would be great!
> >
> > Greg