Subject | RE: [ib-support] Re: Getting id of last inserted record |
---|---|
Author | Wilson, Fred |
Post date | 2003-04-28T20:43:13Z |
Here's an example of a "insert" stored procedure, similiar to one of many
that we use..
The USER and PASSWORD, of course aren't 'XXXX', but are the real strings..
This is just an example of how to get the ID back.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CONNECT "hubba:d:\intrbase\5.8.0\ga"
USER "xxxx" PASSWORD "xxxxx";
SET TERM !!;
CREATE PROCEDURE sp_AddtMachineRecord
(
NAME ARCHAR (32),
DESCRIPTION VARCHAR (60),
feederCount integer,
MachineTypeID INTEGER,
miltsID INTEGER,
SerialNumber VARCHAR (32),
GUITypeID INTEGER ,
AIMCount INTEGER
)
RETURNS
(
machineID INTEGER
)
AS
BEGIN
machineid = gen_id( machineid_gen, 1 );
INSERT INTO MACHINE
(
machineID,
name,
description,
feederCount,
machineTypeID,
miltsID,
serialnumber ,
monitor ,
GUITypeID ,
AIMCount
)
VALUES
(
:machineid,
:NAME,
:DESCRIPTION,
:feederCount,
:machineTypeID,
:miltsID,
:serialnumber ,
1,
:GUITypeID ,
:AIMCount
);
SUSPEND;
END !!
SET TERM ; !!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----Original Message-----
From: hay77772000 [mailto:david.hay@...]
Sent: Monday, April 28, 2003 1:27 PM
To: ib-support@yahoogroups.com
Subject: [ib-support] Re: Getting id of last inserted record
Okay....how would I do that?! Never created stored procedure
before! 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.
Thanks very much,
David
--- In ib-support@yahoogroups.com, "Robert DiFalco" <rdifalco@t...>
wrote:
<http://rd.yahoo.com/M=229633.3212141.4526654.2595810/D=egroupweb/S=1>
705
ftd2+
86:
<http://us.rmi.yahoo.com/rmi/http://www.ft>
d.c
<http://us.adserver.yahoo.com/l?M=229633.3212141.4526654.2595810/D=egroupmai
l/S=:HM/A=1556779/rand=375633351>
To unsubscribe from this group, send an email to:
ib-support-unsubscribe@egroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> .
[Non-text portions of this message have been removed]
that we use..
The USER and PASSWORD, of course aren't 'XXXX', but are the real strings..
This is just an example of how to get the ID back.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CONNECT "hubba:d:\intrbase\5.8.0\ga"
USER "xxxx" PASSWORD "xxxxx";
SET TERM !!;
CREATE PROCEDURE sp_AddtMachineRecord
(
NAME ARCHAR (32),
DESCRIPTION VARCHAR (60),
feederCount integer,
MachineTypeID INTEGER,
miltsID INTEGER,
SerialNumber VARCHAR (32),
GUITypeID INTEGER ,
AIMCount INTEGER
)
RETURNS
(
machineID INTEGER
)
AS
BEGIN
machineid = gen_id( machineid_gen, 1 );
INSERT INTO MACHINE
(
machineID,
name,
description,
feederCount,
machineTypeID,
miltsID,
serialnumber ,
monitor ,
GUITypeID ,
AIMCount
)
VALUES
(
:machineid,
:NAME,
:DESCRIPTION,
:feederCount,
:machineTypeID,
:miltsID,
:serialnumber ,
1,
:GUITypeID ,
:AIMCount
);
SUSPEND;
END !!
SET TERM ; !!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----Original Message-----
From: hay77772000 [mailto:david.hay@...]
Sent: Monday, April 28, 2003 1:27 PM
To: ib-support@yahoogroups.com
Subject: [ib-support] Re: Getting id of last inserted record
Okay....how would I do that?! Never created stored procedure
before! 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.
Thanks very much,
David
--- In ib-support@yahoogroups.com, "Robert DiFalco" <rdifalco@t...>
wrote:
> What about using a stored procedure instead of a trigger? Thestored
> procedure could return the generated value that was used to set theand
> identity column.
>
> -----Original Message-----
> From: hay77772000 [mailto:david.hay@e...]
> Sent: Monday, April 28, 2003 1:22 PM
> To: ib-support@yahoogroups.com
> Subject: [ib-support] Getting id of last inserted record
>
>
> Hi. Am still continuing to port our system from mySQL to
> Firebird.
>
> Have set up the database correctly, along with generators
> triggers that simulate an autoincrement field.< http://rd.yahoo.com/M=229633.3212141.4526654.2595810/D=egroupweb/S=1
>
> However, I still need a way to get the id back of the record
> just
> inserted, in a distributed, multiple-user environment.
>
> Can anyone let me know how to do so, please? I understand I
> could
> use SELECT GEN_ID(GEN_ATABLE, 0) FROM RDB$DATABASE; but that
> this
> cannot be relied on with other transactions etc..
>
> Thanks,
>
> David
>
>
>
>
>
> Yahoo! Groups Sponsor
>
>
<http://rd.yahoo.com/M=229633.3212141.4526654.2595810/D=egroupweb/S=1>
705
> 115386:HM/A=1556779/R=0/* http://shop.store.yahoo.com/cgi-bin/clink?<http://shop.store.yahoo.com/cgi-bin/clink?>
ftd2+
>shopping:dmad/M=229633.3212141.4526654.2595810/D=egroupweb/S=17051153
86:
>HM/A=1556779/R=1/1051561355+ http://us.rmi.yahoo.com/rmi/http://www.ft
<http://us.rmi.yahoo.com/rmi/http://www.ft>
d.c
> om/rmi-framed-url/ http://www.ftd.com/yahoo36 <http://www.ftd.com/yahoo36>M=229633.3212141.4526654.2595810/D=egrou
>
>
> < http://us.adserver.yahoo.com/l? <http://us.adserver.yahoo.com/l?>
> pmail/S=:HM/A=1556779/rand=309980560><http://docs.yahoo.com/info/terms/> > .
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service < http://docs.yahoo.com/info/terms/
>Yahoo! Groups Sponsor
>
>
>
> [Non-text portions of this message have been removed]
<http://us.adserver.yahoo.com/l?M=229633.3212141.4526654.2595810/D=egroupmai
l/S=:HM/A=1556779/rand=375633351>
To unsubscribe from this group, send an email to:
ib-support-unsubscribe@egroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> .
[Non-text portions of this message have been removed]