Subject Re: [Firebird-Java] Get generator field value
Author Helen Borrie
At 10:31 AM 7/09/2005 +0200, you wrote:
> > I want to append a record to a table where the key field has a generator
> > defined in the Firebird database.
> >
> > I can not retrieve the generated value, and I cannot append records
> > without assigning the key field a value.
> >
> > Is this done in the dataset definitions, or is there a method to get the
> > generated value?
>
>To get the next value of the generator you can use
>
>SELECT gen_id(generator_name, 1) FROM rdb$database
>
>The second parameter is the "size" of the ID block (1 - single ID, 10 - ten
>sequential IDs).
>
>If you do not need the generated value later in your application, you can
>use following:
>
>CREATE TABLE bla(
> id INTEGER NOT NULL DEFAUL gen_id(some_generator, 1) PRIMARY KEY,
> col1 ...,
> col2 ...,
> ...
>)

This won't work. You need to do this with a BEFORE INSERT trigger. See
http://firebird.sourceforge.net/index.php?op=faq#q0011.dat

Helen