ESQL/C 5.00.UC2 insert SERIAL weirdness
Posted in 1993
I hope someone can explain the following bizzare phenomenon. I have two tables: foo ( ..., id serial not null unique, ... ) bar ( ..., id serial not null unique, ... ) where a typedef has been appropriately defined for a structure corresponding to each table, and two functions (error checking ommited here): long ins_foo (f) $parameter foo_t *f; { static int prepared; long id; if (! prepared++) { $prepare pf from "insert into foo values (?, ?, ?); $declare cf cursor for pf; } $open cf; $put cf using :*f; after_put: /* id = sqlca.sqlerrd[1]? */ $close cf; after_close: /* id = sqlca.sqlerrd[1]? */ return (id); } and bar() is just like foo(), except that bar-type objects are inserted. Now, in one function the serial value is available in sqlca.sqlerrd[1] immediately after the $put. BUT, in the other function the serial value is only available after the $close. I can understand one behaviour or the other (and prefer the post-put one), but why on earth should they be different? How can I predict where I am supposed to get the value? (Note that the close removes the value in the post-put case). One thing that *might* provide a clue is that the post-put table contains a BYTE column (in the table space) while the post-close table does not. Any insight into this would be appreciated. Thanks, Andrew Shaw AT&T Bell Labs andrew.shaw@att.com