Subject | RE: [ib-support] Re: getting the generated ID |
---|---|
Author | Bill Morrison |
Post date | 2001-12-13T20:56:54Z |
In IBO's case it pulls the ID from the server (a generator on the server).
Thus it is safe.
If you're looking for another way, you could always use a stored procedure
to insert the record and return the ID.
Bill
-----Original Message-----
From: zifnabbe [mailto:zifnabbe@...]
Sent: Thursday, December 13, 2001 12:36 PM
To: ib-support@yahoogroups.com
Subject: [ib-support] Re: getting the generated ID
Isn't it dangerous to allow the client to generate an ID?
Bummer, pitty it isn't possible. I know MySQL has a way of determing
it. Now I need to find another solution.
Tom.
Thus it is safe.
If you're looking for another way, you could always use a stored procedure
to insert the record and return the ID.
Bill
-----Original Message-----
From: zifnabbe [mailto:zifnabbe@...]
Sent: Thursday, December 13, 2001 12:36 PM
To: ib-support@yahoogroups.com
Subject: [ib-support] Re: getting the generated ID
Isn't it dangerous to allow the client to generate an ID?
Bummer, pitty it isn't possible. I know MySQL has a way of determing
it. Now I need to find another solution.
Tom.
--- In ib-support@y..., Lucas Franzen <luc@r...> wrote:
>
>
> zifnabbe schrieb:
> >
> > Hi,
> >
> > How can I get the generated key after inserting a record?
> > Ie. I need to know which value firebird gave to the inserted
record,
> > this value will be used in an application. This to avoid
refreshing
> > the data everytime when a new record is generated.
> >
> > Is this possible?
>
> Yes, but in this case you have to generate the value on the client
side.
>
> It depends how youre using Interbase. If you use IBObjects it's
quite
> easy, by using the GeneratorLinks or the Gen_ID function the
> IB_Connection.
>
> If you're not using IBObjetcs there are several ways to do it, for
> example:
>
> 1. You can get a generator value from a Query by:
> SELECT GEN_ID ( <GENERATORNAME>, 1 ) FROM RDB$DATABASE
>
> 2. You can write a stored procedure that can handle all generators
you
> have like:
> create procedure sp_genid ( GENNAME VARCHAR(31) )
> RETURNS ( NEW_ID INTEGER )
> as
> begin
> if ( GENNAME = 'GENERATOR_1' ) THEN NEW_ID = GEN_ID (
> G_GENERATOR_1, 1 );
> else if ( GENNAME = 'GENERATOR_2' ) THEN NEW_ID = GEN_ID (
> G_GENERATOR_2, 1 );
> else if ( GENNAME = 'GENERATOR_3' ) THEN NEW_ID = GEN_ID (
> G_GENERATOR_3, 1 );
> ... and so on ....
> end
>
> and surely there are several other ways.
>
> But if you're assigning the generator value on server side (ie
within a
> BEFORE INSERT trigger) there's no way to get the value back to the
> client (unless you can identify your inserted record uniquely by
another
> value and select it this way)
>
> HTH
>
> Luc.
To unsubscribe from this group, send an email to:
ib-support-unsubscribe@egroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/