Re: Retrieving correct SERIAL number of new row
Posted in 1997
PRO wrote:
>
> After I insert a row containing a "SERIAL" column, how do I retrieve the
> "serial number" of that row (I need to record that number elsewhere).
>
> I especially have a problem since multiple people may be inserting rows
> very close to simultaneously; the row I insert may not be the last row
> (highest SERIAL number) by the time I read it out.
>
Informix provides the SQLCA record as a very valuable tool in 4gl. In
particular:
SQLCA.SQLERRD[2] = the serial value returned
SQLCA.SQLERRD[3] = number of rows processed
SQLCA.SQLERRD[4] = rowid of the last row
SQLCA.SQLCODE = Error code status of last stmt.
Thus:
INSERT INTO tablename VALUES(g_tablename.*)LET serial_no_assigned = SQLCA.SQLERRD[2]
works for you.
Also helpful (though not at all what you asked):
UPDATE tablename SET ... WHERE ...LET num_rows_updated = SQLCA.SQLERRD[3]
This can help you test for what you expected. For example, you could
have updated 0 rows, but also have no error in the UPDATE statement, and
therefore not notice anything testing with SQLCA.SQLCODE or STATUS.
--Hope these are helpful
Tim