Thanx for help with serial insert in ESQL/C
Posted in 1993
hi, Here is the solution to the problem that I posted. Thanx to all who responded to my post. Here is the solution and once again thanx to every one who responded. I appreciate your help. Solution: ---------------------------------------------------------------------- Check out the SQLCA record structure. sqlca.sqlerrd[1]. This record contains the value you require immediately after the insert. Regards Steve ----------------------------------------------------------------------------- Steve Weet - European Mis - Motorola Cellular Subscriber Group An example of how to use it: -------------------------------------------------------------- Here is a code example I've used in the past: /* generate a serial value, then insert into another table */ #include <stdio.h> $include sqlca; main(argc, argv) int argc; char **argv; { $static long db_num; $database bb1; /* bb1 is a table with a serial column and integer column */ $insert into bb1 values (0,1); if (sqlca.sqlcode) { fprintf(stderr, "%s: Error generating serial number == %d\\n", argv[0], sqlca.sqlcode); exit(2); } else /* sqlca.sqlerrd[1] contains the serial value from the insert stmt */ db_num = sqlca.sqlerrd[1]; printf("serial value: %d\\n", db_num); /* bb2 is a table with a single integer column */ $insert into bb2 values ($db_num); if (sqlca.sqlcode) { fprintf(stderr, "%s: Error inserting data == %d\\n", argv[0], sqlca.sqlcode); exit(2); } } Hope this helps... -- *-------------------------------------------------------------------* \\ Ricky Johnson Intergraph Corp. \\ \\ ricky@epic.b30.ingr.com Huntsville, AL \\ \\ (205)730-3634 Informix Database Support \\ *-------------------------------------------------------------------* -- Potluri Dora Information Systems Lab Clemson University Clemson, sc 29631