home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_07_04 / v7n4109a.txt < prev   
Text File  |  1989-03-02  |  4KB  |  189 lines

  1. Listing 1
  2.  
  3.  
  4. create database task;
  5.  
  6.     database created.
  7.  
  8. create table tasks
  9. (
  10.     item_nosmallint,
  11.     description     char(56),
  12.     due_date        date,
  13.     start_date      date,
  14.     hours  smallint,
  15.     status char(8),
  16.     who    char(10)
  17. );
  18.  
  19.     table created.
  20.  
  21. create unique index taskind on tasks (item_no);
  22.  
  23.     index created.
  24.  
  25. delete from tasks;
  26.  
  27.     1 row(s) deleted.
  28.  
  29. insert into tasks
  30.     (item_no,description,due_date,start_date,hours,status,who) 
  31. values
  32.     (1,"baseline","01/01/90","01/01/89",1000,"on time","all");
  33.  
  34.     1 row(s) inserted.
  35.  
  36. select * from tasks;
  37.  
  38.     item_no      1
  39.     description  baseline
  40.     due_date     01/01/1990
  41.     start_date   01/01/1989
  42.     hours        1000
  43.     status       on time
  44.     who all
  45.  
  46.     1 row(s) retrieved.
  47.  
  48. insert into tasks
  49.     (item_no,description,due_date,start_date,hours,status,who) 
  50. values
  51.     (2,"cleanup","12/31/89","12/01/89",100,"scheduled","all");
  52.  
  53.     1 row(s) inserted.
  54.  
  55. select * from tasks;
  56.  
  57.     item_no      1
  58.     description  baseline
  59.     due_date     01/01/1990
  60.     start_date   01/01/1989
  61.     hours        1000
  62.     status       on time
  63.     who all
  64.  
  65.     item_no      2
  66.     description  cleanup
  67.     due_date     12/31/1989
  68.     start_date   12/01/1989
  69.     hours        100
  70.     status       schedule
  71.     who all
  72.  
  73.     2 row(s) retrieved.
  74.  
  75. update tasks set status = <169>late<170> where item_no = 1;
  76.  
  77.     1 row(s) updated.
  78.  
  79. select * from tasks;
  80.  
  81.     item_no      1
  82.     description  baseline
  83.     due_date     01/01/1990
  84.     start_date   01/01/1989
  85.     hours        1000
  86.     status       late
  87.     who all
  88.  
  89.     item_no      2
  90.     description  cleanup
  91.     due_date     12/31/1989
  92.     start_date   12/01/1989
  93.     hours        100
  94.     status       schedule
  95.     who all
  96.  
  97.     2 row(s) retrieved.
  98.  
  99. delete from tasks where item_no = 2;
  100.  
  101.     1 row(s) deleted.
  102.  
  103. select * from tasks;
  104.  
  105.     item_no      1
  106.     description  baseline
  107.     due_date     01/01/1990
  108.     start_date   01/01/1989
  109.     hours        1000
  110.     status       late
  111.     who all
  112.  
  113.     1 row(s) retrieved.
  114.  
  115.  
  116.  
  117. Listing 2
  118.  
  119. struct sqlca_s 
  120. {
  121.     long sqlcode; /* error message number */
  122.     char sqlerrm[72]; /* error message info */
  123.     char sqlerrp[8];
  124.     long sqlerrd[6];
  125.         /* 0 - reserved */
  126.         /* 1 - serial value after insert */
  127.         /* 2 - number of rows processed */
  128.         /* 3 - reserved */
  129.         /* 4 - offset into string with error */
  130.         /* 5 - rowid after insert */
  131.     struct sqlcaw_s
  132.     {
  133.         char sqlwarn0; /* = W if any sqlwarn[1-7] = W */
  134.         char sqlwarn1; /* = W on truncation occurred  */
  135.         char sqlwarn2; /* = W for null value returned */
  136.         char sqlwarn3; /* = W if select list != into list */
  137.         char sqlwarn4; /* = W if no where clause */
  138.         char sqlwarn5; /* reserved */
  139.         char sqlwarn6; /* reserved */
  140.         char sqlwarn7; /* reserved */
  141.     };
  142.     struct sqlcaw_s sqlwarn;
  143. };
  144. extern struct sqlca_s sqlca;
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. #include <stdio.h>
  152.  
  153. $include sqlca; 
  154. $include sqlda;
  155.  
  156. $char *ptr; 
  157. $char *who; 
  158. $char itemno[8]; 
  159. $char status[12];
  160.  
  161. main(argc, argv) 
  162. int argc; 
  163. char *argv[]; 
  164. {
  165.     ptr = "select status, item_no from customer where who matches ?";
  166.     who = argv[1];
  167.     $database task;
  168.     if (!sqlca.sqlcode)
  169.         $prepare s_name from $ptr;
  170.     if (!sqlca.sqlcode)
  171.         $declare kursor cursor for s_name;
  172.     if (!sqlca.sqlcode)
  173.         $open kursor using $who;
  174.     if (!sqlca.sqlcode)
  175.     {
  176.         for ( ; ; )
  177.         {
  178.    $fetch kursor into $status, $itemno;
  179.    if (sqlca.sqlcode)
  180.        break;
  181.    printf("%s %s\n", status, itemno);
  182.         }
  183.         $close kursor;
  184.     }
  185.     else
  186.         printf("ESQL command error %ld\n", sqlca.sqlcode);
  187.  }
  188.  
  189.