]> andersk Git - moira.git/blob - gdb/tdbcl.c
a015d6dc060033590641de0ebc8623d47f25d3f0
[moira.git] / gdb / tdbcl.c
1 /*
2  *      $Source$
3  *      $Header$
4  */
5
6 #ifndef lint
7 static char *rcsid_tdbcl_c = "$Header$";
8 #endif  lint
9
10 /************************************************************************/
11 /*      
12 /*                        tdbcl (test database client)
13 /*                        ----------------------------
14 /*      
15 /*      Author: Noah Mendelsohn (IBM T.J. Watson Research and MIT Project
16 /*                               Athena)
17 /*      
18 /*      Copyright: 1986 MIT Project Athena
19 /*      
20 /************************************************************************/
21 /*      
22 /*      PURPOSE
23 /*      -------
24 /*      
25 /*      A GDB client program which accesses a relational database
26 /*      using the services of GDB.
27 /*      
28 /************************************************************************/
29
30
31 #include <stdio.h>
32 #include "gdb.h"
33
34 \f
35
36 int ftypes[] = {STRING_T, INTEGER_T, INTEGER_T};
37 char *fnames[] = {"name", "rank", "serial"};
38 int
39 main(argc, argv)
40 int argc;
41 char *argv[];
42 {
43
44         /*----------------------------------------------------------*/
45         /*      
46         /*                      DECLARATIONS
47         /*      
48         /*----------------------------------------------------------*/
49
50         DATABASE db;                            /* this is the database */
51                                                 /* we access */
52         int rc;                                 /* return code from */
53                                                 /* access_db */
54         TUPLE_DESCRIPTOR tpd;
55         RELATION rel;
56 #define MAX_OPS 50
57         OPERATION ops[MAX_OPS];
58         int next_op=0;                          /* next op to use */
59         int i;
60
61         /*----------------------------------------------------------*/
62         /*      
63         /*                  EXECUTION BEGINS HERE
64         /*      
65         /*      Make sure the command line specifies the name
66         /*      of the host on which the server program is running.
67         /*      
68         /*----------------------------------------------------------*/
69
70         if (argc != 3) {
71                /* 
72                 * Tell 'em the syntax
73                 */
74                 fprintf(stderr, "tcl <database-name@host> <query>\n");
75                 exit (4);
76         }
77
78         /*----------------------------------------------------------*/
79         /*      
80         /*      Initialize the GDB library.
81         /*      
82         /*----------------------------------------------------------*/
83
84         gdb_init();
85
86         /*----------------------------------------------------------*/
87         /*      
88         /*      Create all the operations
89         /*      
90         /*----------------------------------------------------------*/
91         for (i=0; i<MAX_OPS; i++)
92                 ops[i] = create_operation();
93 \f
94         /*----------------------------------------------------------*/
95         /*      
96         /*      Try for a connection to the server on the 
97         /*      specified host.
98         /*      
99         /*----------------------------------------------------------*/
100
101         printf("Attempting database: %s\n", argv[1]);
102
103         if (rc = access_db(argv[1], &db) != DB_OPEN) {
104                 fprintf(stderr,"Return code from access_db is %d\n",rc);
105                 exit(8);
106         }
107
108         if (db == NULL) {
109                 fprintf(stderr,"Got null db after access_db reported success\n");
110                 exit(8);
111         }
112
113         /*----------------------------------------------------------*/
114         /*      
115         /*      Try destroying and creating a table
116         /*      
117         /*----------------------------------------------------------*/
118
119         printf("Now queueing operations\n");
120
121         rc = start_performing_db_operation(ops[next_op++],db, "destroy tdbcl");
122
123         rc = start_performing_db_operation(ops[next_op++],db, "create tdbcl (name=c8, rank = i4, serial=i4)");
124
125         /*----------------------------------------------------------*/
126         /*      
127         /*      Append some data to the table
128         /*      
129         /*----------------------------------------------------------*/
130
131         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"noah\", rank = 1, serial=123)");
132         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"mike\", rank = 5, serial=456)");
133         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"mike1\", rank = 5, serial=456)");
134         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"mike2\", rank = 5, serial=456)");
135         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"mike3\", rank = 5, serial=456)");
136         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"mike4\", rank = 5, serial=456)");
137         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"mike5\", rank = 5, serial=456)");
138         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"mike6\", rank = 5, serial=456)");
139         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"mike7\", rank = 5, serial=456)");
140         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"mike8\", rank = 5, serial=456)");
141         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"mike9\", rank = 5, serial=456)");
142         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"mike10\", rank = 5, serial=456)");
143         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"mike11\", rank = 5, serial=456)");
144         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"mike12\", rank = 5, serial=456)");
145         rc = start_performing_db_operation(ops[next_op++],db, "append to  tdbcl (name=\"mike13\", rank = 5, serial=456)");
146
147         
148         /*----------------------------------------------------------*/
149         /*      
150         /*      Complete the operations and print the return codes 
151         /*      from them
152         /*      
153         /*----------------------------------------------------------*/
154
155         printf("Operations have been queued, waiting for last one to complete\n");
156         complete_operation(ops[next_op-1]);
157         for (i=0; i<=next_op; i++)
158                 printf("%d: status=%d, result=%d\n", i, OP_STATUS(ops[i]),
159                        OP_RESULT(ops[i]));
160
161         /*----------------------------------------------------------*/
162         /*      
163         /*      Do a query
164         /*      
165         /*----------------------------------------------------------*/
166
167         tpd = create_tuple_descriptor(3, fnames, ftypes);
168
169         rel = create_relation(tpd);
170
171         rc = db_query(db, rel, /*argv[2]*/ "(>*name*<=tdbcl.name, >*serial*<=tdbcl.serial) where tdbcl.serial>200");
172
173         printf("return code from query is %d\n",rc);
174         if (rc == 0)
175                 print_relation("Query result", rel);
176
177         delete_relation(rel);
178         rel = create_relation(tpd);
179
180         rc = db_query(db, rel, /*argv[2]*/ "(>*name*<=tdbcl.name, >*serial*<=tdbcl.serial) where tdbcl.serial>200");
181
182         printf("return code from query is %d\n",rc);
183         if (rc == 0)
184                 print_relation("Query result", rel);
185
186         delete_relation(rel);
187         delete_tuple_descriptor(tpd);
188
189         return;
190 }
191                         
This page took 0.067851 seconds and 3 git commands to generate.