Serial fields
Posted in 1999
Topics: General Discussion
Hi all! When you insert a new record in an Informix table, and if the table contains a serial field, the next serial number is not calculated until you post the record to the table. Is this true? Is there any way to know what the next serial number will be after inserting a new record, but before saving the record to the table? I will appreciate any comment or hint.
Sergio López wrote: > > Hi all! > > When you insert a new record in an Informix table, and if the table > contains a serial field, the next serial number is not calculated until > you post the record to the table. Is this true? > > Is there any way to know what the next serial number will be after > inserting a new record, but before saving the record to the table? > > I will appreciate any comment or hint. If you are using a singleton INSERT statement the serial number will be in the sqlca structure field sqlerrd[2] immediately after the insert. If you are using an INSERT CURSOR and PUT then when the PUT buffer flushes, or if you explicitely run 'FLUSH cursor_name' the sqlerrd[2] field will be set to the serial number of the LAST row inserted from the flushed buffer immediately after the FLUSH or the PUT which caused the buffer to fill and auto flush. Of course you cannot reasonably assume the serial numbers of ANY of the other rows in the buffer, in general, so if you need to know the serial number of a particular row, and are using an INSERT CURSOR you MUST FLUSH after each PUT so that you can get the serial from sqlerrd[2] after the FLUSH. Alternatively you can: SELECT DBINFO( "sqlca.sqlerrd" ) FROM systables where tabid = 99; Immediately after the INSERT/PUT/FLUSH to get the serial number of the row most recently inserted by your session. Art S. Kagel