Subject Re: [firebird-support] Re: How to detect a record changed between read and update?
Author Martijn Tonies
Hi,

> > There are many different ways.
>
> The best will do, thank you.
>
> > The easiest is to use snapshot transaction (which is default).
> > Since snapshot provides consistent view of whole database,
> > it can't see changes that happened after its start,
> > thus in this transaction you can't update such records.
> >
> > Ivan
>
> You mean I shouldn't do this? You can't start a transaction in a sp,
> right?

No, you can't. But the SP will run in the transaction context
that executed it.

Another way of checking for changes is as such:

UPDATE mytable
SET mycolumn = newvalue
WHERE mycolumn = oldvalue
AND pkcolumn = pkvalue

Now, if someone else changed "mycolumn", then this UPDATE
will return a "rows affected" of 0 -> hence, someone else changed
it.

In old "bde" speak, this was an "update-where-all" with the
TUpdateSQL component.

With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com