Subject Re: [IBO] Autoinc field value unknown after insert+post+commit
Author Woody
----- Original Message -----
From: "jrp_public" <jrp_public@...>
> Dear IBO users,
>
> I am new to Firebird and IBO.
>
> I have a very basic problem that I have been fighting
> for some hours without success (doh!)
>
> Please somebody help me as my curiosity is killing me :)
>
> The story
> =========
> I have a table with an autoincrementing field which I use as a
> primary key. The autoincrementing is the common trigger + generator
> thing, which I have verified worked correctly. I use an IB_Query to
> access this table (no joins involved). The transaction isolation is
> tiCommitted.
>
>
> The problem
> ===========
> After posting a newly-inserted record, the value of the autoinc field
> is NULL.

The simplest way to deal with generators and key fields is to let the
IB_Query do the work for you. Simply set the GeneratorLinks property by
specifying the field(s) that require a generator. The IB_Query will get the
generator value and set the field accordingly for new records. The trigger
does not need to set the field unless it is null. Structure the trigger to
test for this as in :

if (NEW.KEYFIELD IS NULL) then
NEW.KEYFIELD = GEN_ID(gen_whatever, 1);

Also, make sure you set the KeyLinks property to specify all the fields
making each record unique.

HTH

Woody (TMW)