Subject | [firebird-support] Getting value of ID |
---|---|
Author | Alex Taylor |
Post date | 2005-04-14T07:10:40Z |
Hi all!
Is this a safe implementation of getting primary key value inside a SP?
Or is there a chance for getting wrong values? Is it possible for other
users to insert additional records between the insert and the call to
GEN_ID (inside the same proc.)? Of course there is a BEFORE INSERT
trigger with appropriate code to generating the primary key value from a
generator, if it is not passed in the insert values.
CREATE TRIGGER TABLE_NAME_BI FOR TABLE_NAME
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.ID IS NULL) THEN
NEW.ID = GEN_ID(TABLE_NAME_ID,1);
END
|CREATE PROCEDURE TABLE_NAME_I(
INPUT_PARAMS...)
RETURNS (
ID INTEGER)
AS
BEGIN
INSERT INTO TABLE_NAME (FIELD_LIST)
VALUES (VALUE_LIST);
ID=GEN_ID(GEN_TABLE_NAME_ID,0);
END
TIA:Alex
|
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.9.9 - Release Date: 2005.04.13.
Is this a safe implementation of getting primary key value inside a SP?
Or is there a chance for getting wrong values? Is it possible for other
users to insert additional records between the insert and the call to
GEN_ID (inside the same proc.)? Of course there is a BEFORE INSERT
trigger with appropriate code to generating the primary key value from a
generator, if it is not passed in the insert values.
CREATE TRIGGER TABLE_NAME_BI FOR TABLE_NAME
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.ID IS NULL) THEN
NEW.ID = GEN_ID(TABLE_NAME_ID,1);
END
|CREATE PROCEDURE TABLE_NAME_I(
INPUT_PARAMS...)
RETURNS (
ID INTEGER)
AS
BEGIN
INSERT INTO TABLE_NAME (FIELD_LIST)
VALUES (VALUE_LIST);
ID=GEN_ID(GEN_TABLE_NAME_ID,0);
END
TIA:Alex
|
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.9.9 - Release Date: 2005.04.13.