Subject | Re: [firebird-support] Slq Server @@IDENTITY equivalent in FB |
---|---|
Author | Dragos Hilbert |
Post date | 2006-08-22T05:37:44Z |
@@IDENTITY "equivalent" with GEN_ID(AS_USERS_SEQ, 0), but PLEASE do not use
on production programs.
For your case:
On client execute: GEN_ID(AS_USERS_SEQ, 1) to have a new id then Insert into
<Table>(USER_ID, ....) Values( :USER_ID, .....
( :USER_ID is new ID for your table generated with AS_USERS_SEQ )
Or:
On client execute: Insert into <Table>(, ....) Values(....) then make an
refresh with
Select USER_ID, .....
From <Table>
Where <CandidateKey>=:CandidateKeyValue ( you need an CandidateKey )
Or ( Microsoft style :) ):
A SP like:
Create procedure UserIU( FIeld1 ..., Field2....)
Returns ( USER_ID int )
as
begin
:USER_ID = GEN_ID(AS_USERS_SEQ, 1);
insert into ...........
suspend;
end
I use first solution.
Read more on:
http://www.delphifaq.com/faq/databases/interbase/f10.shtml
http://www.ibphoenix.com/main.nfs?a=ibphoenix&d=kb&q=generator
http://www.ibphoenix.com/main.nfs?a=ibphoenix&d=kb&q=suspend about
"Suspend"
on production programs.
For your case:
On client execute: GEN_ID(AS_USERS_SEQ, 1) to have a new id then Insert into
<Table>(USER_ID, ....) Values( :USER_ID, .....
( :USER_ID is new ID for your table generated with AS_USERS_SEQ )
Or:
On client execute: Insert into <Table>(, ....) Values(....) then make an
refresh with
Select USER_ID, .....
From <Table>
Where <CandidateKey>=:CandidateKeyValue ( you need an CandidateKey )
Or ( Microsoft style :) ):
A SP like:
Create procedure UserIU( FIeld1 ..., Field2....)
Returns ( USER_ID int )
as
begin
:USER_ID = GEN_ID(AS_USERS_SEQ, 1);
insert into ...........
suspend;
end
I use first solution.
Read more on:
http://www.delphifaq.com/faq/databases/interbase/f10.shtml
http://www.ibphoenix.com/main.nfs?a=ibphoenix&d=kb&q=generator
http://www.ibphoenix.com/main.nfs?a=ibphoenix&d=kb&q=suspend about
"Suspend"
On 8/22/06, Vlad Orlovsky <vmo3d@...> wrote:
>
> Hi Everyone,
>
> I'm still on the process of porting SQL Server DB to
> Firebird.
>
> Does anyone knows of a SQL Server @@IDENTITY
> equivalent in Firebird.
>
> Basically I have:
>
> Active BEFORE INSERT trigger for AS_USERS at position
> 0
> AS BEGIN
> IF (NEW.USER_ID IS NULL) THEN
> NEW.USER_ID = GEN_ID(AS_USERS_SEQ, 1);
> END
>
> After I do my INSERT, I need to know the value of
> USER_ID to return back to the caller program.
>
> I'm using Fb 1.5(if that helps)
>
> Thank you once again,
> Vlad
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://www.firebirdsql.org and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
--
-- \nBest regards,\n Dragos Hilbert mailto:
dragos.hilbert@...\n
-------
[Non-text portions of this message have been removed]