Subject | Re: [firebird-support] Getting value of ID |
---|---|
Author | Martijn Tonies |
Post date | 2005-04-14T07:15:08Z |
Hello Alex,
Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server
Upscene Productions
http://www.upscene.com
> Is this a safe implementation of getting primary key value inside a SP?No.
> Or is there a chance for getting wrong values?Yes.
>Is it possible for otherExactly.
> users to insert additional records between the insert and the call to
> GEN_ID (inside the same proc.)?
>Of course there is a BEFORE INSERTID = gen_id(gen_table_name_id, 1);
> 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 (id, FIELD_LIST)With regards,
> VALUES (:id, VALUE_LIST);
>
> END
Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server
Upscene Productions
http://www.upscene.com