Subject Re: [firebird-support] Generator Fires Twice??
Author Helen Borrie
At 06:17 PM 9/08/2005 +0000, Sam Hunt wrote:

>The following statement used to work.
>(pg 648 Helen's book)
>
>sql.add('SELECT GEN_ID(GEN_PK_CONSTITUENTS,1) AS RESULT FROM
>RDB$DATABASE');
>
>and did exactly what it was supposed to do - grab the new record ID
>created by the GEN_PK_CONSTITUENTS generator when the BI trigger
>fired.

No, it never did that. What it did (does) do is to pull a new value from
the generator for the client program to use. It has absolutely no
connection to the the BI trigger.


>Now, I get the following error when I attempt to trace (in Delphi)
>thru this line of code:
>"SQL error code = -104
>Unexpected end of command'.

This part of the problem lies somewhere in your Delphi code. How are you
submitting the statement? What is your API interface component doing with
the statement? Can you put a monitor on it to see the statement that is
being passed across the API?


>Also, the trigger value is destroyed and the above statement causes a
>new value to be created.

This part of the problem is due to not having the BI trigger test the
new.value for NULL before deciding whether to grab a new value from the
generator. Go back to P. 647 and start at the heading "Implementing
Auto-Incrementing Keys".

./heLen