home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0210 - 0219 / ibm0210-0219 / ibm0213.tar / ibm0213 / 7025PWA1.ZIP / SAMPLES.ZIP / SQLLIB / SAMPLES / C / DOSINT.SQC < prev    next >
Encoding:
Text File  |  1994-02-28  |  3.6 KB  |  152 lines

  1. /* C test program */
  2.  
  3. #include <sqlenv_.h>
  4. #include <sql_.h>
  5. #include <sqlca_.h>
  6. #include <sqlda_.h>
  7. #include <sqlutil_.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include <signal.h>
  13. #include <conio.h>
  14. #include <dos.h>
  15.  
  16.  
  17. EXEC SQL INCLUDE SQLCA;
  18.  
  19. EXEC SQL BEGIN DECLARE SECTION;
  20.  
  21. char results[80];
  22. char query[80];
  23.  
  24. EXEC SQL END DECLARE SECTION;
  25.  
  26.  
  27. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  28. /*   FUNCTION PROTOTYPES                                             */
  29. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  30.  
  31. int fred (void);
  32.  /* Interrupt handler */
  33. void _interrupt _far int_handler (void);
  34.  
  35. int rc;
  36.  
  37. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  38. /*   GLOBAL VARIABLES                                                */
  39. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  40.  
  41. int main (void)
  42. {
  43.   printf ("Begin program\n");
  44.  
  45.   /* Disable interrupts */
  46.   _disable ();
  47.  
  48.   /* Install interrupt handler */
  49.   _dos_setvect (0x23, int_handler);
  50.  
  51.   /* Enable interrupts */
  52.   _enable ();
  53.  
  54.   printf ("Calling fred .... Hi fred \n");
  55.   rc = fred ();
  56.   printf ("We're back \n");
  57.   return rc;
  58. }
  59.  
  60. /********************************************************************/
  61. /* function - int_handler                                           */
  62. /* ctrl-c, ctrl-break interrupt handler function                    */
  63. /********************************************************************/
  64.  
  65. void _interrupt _far int_handler ()
  66. {
  67.  
  68.         /* Terminate query and communications to server */
  69.  
  70.         SQLGINTR ();
  71.         return ;
  72.  
  73. }
  74.  
  75. int fred (void)
  76. {
  77.  
  78.   /* Declarations */
  79.  
  80.   char database[9];
  81.   char alias[9];
  82.   char type;
  83.   char nodename[9];
  84.   char drive;
  85.   char comment[20];
  86.   short codepg;
  87.  
  88.   /* Initializations */
  89.  
  90.   codepg = 0;
  91.   drive = '0';
  92.   strcpy (comment, "");
  93.   strcpy (nodename, "KEYNES");  /* SERVER NETBIOS NAME */
  94.   strcpy (database, "SAMPLE");
  95.   strcpy (alias, "SAMPLE");
  96.   type = '1';
  97.  
  98.   /* Catalog database */
  99.  
  100.   sqlecatd (database, alias, type, nodename, drive, comment, codepg, &sqlca);
  101.   if (SQLCODE != 0)
  102.       printf ("An error occurred in SQLECATD with rc = %ld\n",SQLCODE);
  103.   else
  104.       printf ("Succesful catalog ..... \n");
  105.  
  106.   /* Start using database */
  107.  
  108.   sqlestrd (database, SQL_USE_SHR, &sqlca);
  109.   if (SQLCODE != 0) {
  110.     printf("An error occurred in SQLESTRD with rc = %ld\n", SQLCODE);
  111.     printf("SQLERRMC = %s\n", sqlca.sqlerrmc);
  112.     printf("SQLERRP    = %s\n", sqlca.sqlerrp);
  113.     printf("SQLERRD    = %ld\n", sqlca.sqlerrd);
  114.     printf("SQLWARN   = %s\n",SQLWARN1);
  115.   } else {
  116.      printf("Succesful start using database ..... \n");
  117.   } /* endif */
  118.  
  119.   /* Perform query */
  120.  
  121.   EXEC SQL DECLARE c1 CURSOR FOR s1;
  122.   printf ("Return from SQL DECLARE = %ld\n", SQLCODE);
  123.  
  124.   strcpy (query, "SELECT name FROM userid.staff ORDER BY name");
  125.   EXEC SQL PREPARE s1 FROM :query;
  126.   printf ("Return from SQL PREPARE = %ld\n", SQLCODE);
  127.  
  128.   EXEC SQL OPEN c1;
  129.   printf ("Return from SQL OPEN = %ld\n", SQLCODE);
  130.  
  131.   EXEC SQL FETCH c1 INTO :results;
  132.   printf ("Return from SQL FETCH .... %ld\n",SQLCODE);
  133.  
  134.   while (SQLCODE == 0) {
  135.     printf ("Results = %s\n", results);
  136.     EXEC SQL FETCH c1 INTO :results;
  137.   };
  138.  
  139.   EXEC SQL CLOSE c1;
  140.  
  141.   /* Uncatalog database */
  142.  
  143.   sqleuncd ( database, &sqlca );
  144.   if (SQLCODE != 0)
  145.       printf("An error occurred in SQLEUNCD with rc = %ld\n", SQLCODE);
  146.   else
  147.       printf("Succesful uncatalog ..... \n");
  148.  
  149.   return(0);
  150. }
  151.  
  152.