home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.databases.informix
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!elroy.jpl.nasa.gov!usc!rpi!gatech!hubcap!dpotlur
- From: dpotlur@hubcap.clemson.edu (Potluri Dora)
- Subject: Thanx for help with serial insert in ESQL/C
- Message-ID: <1993Jan27.004230.18733@hubcap.clemson.edu>
- Keywords: Serial, insert, ESQL/C, Informix SE 5.0, C
- Organization: Clemson University
- Date: Wed, 27 Jan 1993 00:42:30 GMT
- Lines: 65
-
-
- 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
-