Subject | Re: Get current value from generator |
---|---|
Author | Adam |
Post date | 2005-07-26T23:46:19Z |
> How can I getYes but
> the current value without incrementing it? Can I do (gen_name,0)?
*** WARNING ***
It is OK as a general lookup to check its current value as a general
curiousity, but DO NOT USE THIS FOR ANY OTHER READSON.
Calls the the generator are transaction independent.
So if your psql looks like this
insert into tableA (id, name) values (gen_id(gen_tableaid,1), 'Adam');
-- do some stuff
-- oops, I need to get that id I just used in tableA
select gen_id(gen_tableaid,0) from RDB$Database
That is really bad. In fact even if it is on the next row, it is
possible for another transaction to increment the generator BETWEEN
where you incremented it and when you query it.
A better way to get the ID, BEFORE you send the insert statement.
That way you can put it in a variable and use it where needed.
Adam