home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / database / informix / 3070 < prev    next >
Encoding:
Text File  |  1993-01-28  |  2.4 KB  |  76 lines

  1. Newsgroups: comp.databases.informix
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!elroy.jpl.nasa.gov!usc!rpi!gatech!hubcap!dpotlur
  3. From: dpotlur@hubcap.clemson.edu (Potluri Dora)
  4. Subject: Thanx for help with serial insert in ESQL/C
  5. Message-ID: <1993Jan27.004230.18733@hubcap.clemson.edu>
  6. Keywords: Serial, insert, ESQL/C, Informix SE 5.0, C
  7. Organization: Clemson University
  8. Date: Wed, 27 Jan 1993 00:42:30 GMT
  9. Lines: 65
  10.  
  11.  
  12. hi,
  13.     Here is the solution to the problem that I posted.
  14. Thanx to all who responded to my post. 
  15.     Here is the solution and once again thanx to every one who 
  16. responded. I appreciate your help.
  17.  
  18. Solution:
  19. ----------------------------------------------------------------------
  20. Check out the SQLCA record structure. sqlca.sqlerrd[1].
  21. This record contains the value you require immediately after the insert.
  22. Regards
  23. Steve
  24. -----------------------------------------------------------------------------
  25. Steve Weet - European Mis - Motorola Cellular Subscriber Group
  26.  
  27. An example of how to use it:
  28. --------------------------------------------------------------
  29. Here is a code example I've used in the past:
  30. /* generate a serial value, then insert into another table */
  31. #include <stdio.h>
  32. $include sqlca;
  33.  
  34. main(argc, argv)
  35. int argc;
  36. char **argv;
  37. {
  38.  $static long db_num;
  39.  $database bb1;
  40.  
  41.   /* bb1 is a table with a serial column and integer column */
  42.   $insert into bb1 values (0,1); 
  43.  
  44.   if (sqlca.sqlcode) {
  45.       fprintf(stderr, "%s: Error generating serial number == %d\n",
  46.                   argv[0], sqlca.sqlcode);
  47.       exit(2);
  48.    } else
  49.    /* sqlca.sqlerrd[1] contains the serial value from the insert stmt */
  50.       db_num = sqlca.sqlerrd[1];
  51.  
  52.    printf("serial value: %d\n", db_num);
  53.  
  54.    /* bb2 is a table with a single integer column */
  55.    $insert into bb2 values ($db_num);
  56.         if (sqlca.sqlcode) {
  57.                 fprintf(stderr, "%s: Error inserting data == %d\n",
  58.                         argv[0], sqlca.sqlcode);
  59.                 exit(2);
  60.         }
  61. }
  62.  
  63. Hope this helps...
  64. -- 
  65.  *-------------------------------------------------------------------*
  66.   \   Ricky Johnson                           Intergraph Corp.        \
  67.    \    ricky@epic.b30.ingr.com               Huntsville, AL           \
  68.     \     (205)730-3634                       Informix Database Support \
  69.      *-------------------------------------------------------------------*
  70.  
  71. -- 
  72. Potluri Dora
  73. Information Systems Lab  
  74. Clemson University
  75. Clemson, sc 29631
  76.