Subject | Re: Getting id of last inserted record |
---|---|
Author | Aage Johansen |
Post date | 2003-04-29T18:49:07Z |
On Mon, 28 Apr 2003 19:21:24 +0000 (UTC), hay77772000 wrote:
You don't have to use the SP approach. Try something like:
Query1.SQL.Add('select gen_id(GEN_ATABLE, 1) from rdb$database');
Query1.Open;
YOURID := Query1.Fields[0].AsInteger;
Query1.Close;
If you use IBO (or IBX, FIBPlus(?)) there are even easier ways.
(Do the SP as an exercise!)
2.
When you need the generated value, you're not likely to forget about it.
But, it's a good thing to have a trigger as well.
Regards,
Aage J.
> Okay....how would I do that?! Never created stored procedure before!1.
> Also, would I have to use that in the insert statement? With triggers,
> the programmer never has to worry about whether it's autoincrement or
> not.
You don't have to use the SP approach. Try something like:
Query1.SQL.Add('select gen_id(GEN_ATABLE, 1) from rdb$database');
Query1.Open;
YOURID := Query1.Fields[0].AsInteger;
Query1.Close;
If you use IBO (or IBX, FIBPlus(?)) there are even easier ways.
(Do the SP as an exercise!)
2.
When you need the generated value, you're not likely to forget about it.
But, it's a good thing to have a trigger as well.
Regards,
Aage J.