Subject RE: [IBO] Re: Auto-Incrementing Key Field
Author Jack Cane
I'm using TIBOdataBase and tIBOquery with tDataSource and tdbEdit. Cannot
find the OnBeforePost event.

Plse see also, reply to Frank.

I'm pretty new to all of this.


-----Original Message-----
From: Marco Menardi [mailto:mmenaz@...]
Sent: Sunday, October 13, 2002 4:09 PM
Subject: [IBO] Re: Auto-Incrementing Key Field

--- In IBObjects@y..., "Jack Cane" <jwcane@e...> wrote:
> I have configured the key field as an auto-incementing integer. I have
> hooked to a tdbEdit whose read-only property is set to true. When I
> the 'Post' button of my tdbNavigator an exception is raised with
> "(Field name) is a required field".

As far as I remember, the error is a client-side error. If you fill the
autoincrement field only at database level, you have to set that field as
"not required".
The best aproach is having the trigger that assign the field value using a
generator that checks if the field is null (and assigns the value only if
null), and then use the IB_Query.GeneratorLinks property for having the
field value automatically assigned at client level before the post (it's
assigned when you enter the Insert state), or use OnBeforePost to assign the
value to the field (so it's assigned only when/if posted).

the code I suggest in the trigger is like:
IF ((NEW.MovCon_ID IS NULL) OR (NEW.MovCon_ID < 1)) THEN
NEW.MovCon_ID = gen_id(MovCon_ID_GEN, 1);

then '<1' condition is there to let you assign a negative value and escape
a client check for "not null" assignment to that field, in the case you are
using tools like IB_SQL to perform manual manteinance of the database.

For the OnBeforePost, there is a useful property of IB_Query:
with qryMovConRighe do
FieldByName('RIGA_ID').AsInt64 := Gen_ID('RIGA_ID_GEN', 1);
where 'RIGA_ID' is the key field, and 'RIGA_ID_GEN' is the name of the
generator used to fill it.

Marco Menardi

Yahoo! Groups Sponsor

IB Objects - direct, complete, custom connectivity to Firebird or
without the need for BDE, ODBC or any other layer.

___________________________________________________________________________ - your IBO community resource for Tech Info
keyword-searchable FAQ, community code contributions and more !

Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

[Non-text portions of this message have been removed]