Subject Re: [firebird-support] Re: select ..... with lock
Author Ivan Prenosil
> i do this all in an endless loop,
> so i only leave this loop if i got the unlocked record during a read.

It will cause unnecessary load on client+network+server.
Use WAIT transaction instead.

Ivan


----- Original Message -----
From: "rgaustria0709" <robert.graf@...>
To: <firebird-support@yahoogroups.com>
Sent: Wednesday, March 02, 2005 7:38 AM
Subject: [firebird-support] Re: select ..... with lock




--- In firebird-support@yahoogroups.com, Pavel Menshchikov
<mpn2001@y...> wrote:
> Hello,
>
> r> i have one question. how can i decide that a record was locked
with a
> r> select-statement like 'select * from table where ..... with
lock'?
> r> i tried it with a try..except but i didn't work.
> What did you do in your try...except block?
> AFAIK, you have to try to update the record: if that operation
raises
> an exception, the record is locked (not necessarily by SELECT ...
WITH
> LOCK, maybe by common UPDATE). Note that your transaction must be NO
> WAIT to raise the exception.
>
>
> HTH
> --
> Best regards,
> Pavel Menshchikov
> http://www.ls-software.com

hello pavel,

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

ok := false
starttransaction
while not ok do begĂ­n
lock := false
try
select * from table where key = :key with lock
except
lock := true
end
if not lock then begin
inc(number)
update table set number = :number where key = :key
close
commit
ok := true
end
end

i hope this is understandable for you - please don't look at the
syntax of the example - i only want to show you my applied logic of
the program.

best regards
robert graf