Re: Getting serial value of just inserted record
Posted in 1997
> -----Original Message-----
> } Michael J. Erikson wrote:
> } > AndreasSeibt wrote:
> } >
> } > I have to write a stored procedure which inserts a record into a table.
> } > This record has a field of Type SERIAL as primary key. I need the value
> of
> } > the primary key directly after inserting the record for subsequent
> } > processing. Is there any way to get this value?
> } >
> } > I use INFORMIX-Online 7.23.
> }
> } To get the Serial value after an insert use the following
>
> }Define Value Integer;
> }Let Value = dbinfo("sqlca.sqlerrd1");
> }This will set Value to be the value of the last Serial column inserted.
> }
> }Hope this helps.
> } Michael J. Erickson
> }
Guillermo Labatte wrote:
>
> I use Online 5.07. I tried it but it didn't work.
> The error is:
> 674: Procedure (dbinfo) not found.
> 111: ISAM error: no record found.> Is there any solution other than an upgrade?
5.x Oyyyy!
OK, here's one but you not gonna like it! (I certainly don't!)
In the procedure, before you do the insert, lock the table in exclusive
mode. (which may not work - others are on the system) After the insert,
select max(serial_column) into some_variable from your_table;
Remember to unlock the table.
Yuchh!
--
-- Jake (Never yelled "CROWDED THEATER!" during a fire)
+------------------------------------------------------------+
| The expedient performance of a task with excessive concern |
| regarding its duration-to-completion engenders a virtual |
| certainty of diminished benefit therefrom. |
| -- Benjamin Franklin (but he said it in 3 words) |
+------------------------------------------------------------+