Subject Re: [OBORONA-SPAM] [firebird-support] Re: select ..... with lock
Author Pavel Menshchikov
Hello Robert,

r> many thanks for your quick answer. i do this all in an endless loop,
r> so i only leave this loop if i got the unlocked record during a read.
r> in the except block i want to go back to the start of the loop and
r> try to read this record again. in this record were stored a
r> sequential invoice number. this number sould be increased by one and
r> stored in the same record. in the past i had the problem that two
r> invoices got the same number, because the record is not locked. now i
r> tried it with the 'select ..... with lock' statement and now the
r> second try to get this record ended in a programm-abend without any
r> error- or warning-message. i will show you what i do in my programm.

r> ok := false
r> starttransaction
r> while not ok do begĂ­n
r> lock := false
r> try
r> select * from table where key = :key with lock
Probably SELECT WITH LOCK has to raise an exception if the record is
locked already - I'm not sure. You may try dummy UPDATE instead:
update table set key=key where key=:key

r> except
r> lock := true
r> end
r> if not lock then begin
r> inc(number)
r> update table set number = :number where key = :key
r> close
r> commit
r> ok := true
r> end
r> end

r> i hope this is understandable for you - please don't look at the
r> syntax of the example - i only want to show you my applied logic of
r> the program.
Yes, it's quite clear. But I doubt it's a good algorithm: it may
become a bottleneck for large number of simultaneously updating
users. As far as I remember, there is an article about sequental
numbers at IBO site.


HTH
--
Best regards,
Pavel Menshchikov
http://www.ls-software.com