7 static char *rcsid_tdbcl_c = "$Header$";
10 /************************************************************************/
12 /* tdbcl (test database client)
13 /* ----------------------------
15 /* Author: Noah Mendelsohn (IBM T.J. Watson Research and MIT Project
18 /* Copyright: 1986 MIT Project Athena
20 /************************************************************************/
25 /* A GDB client program which accesses a relational database
26 /* using the services of GDB.
28 /************************************************************************/
36 int ftypes[] = {STRING_T, INTEGER_T, INTEGER_T};
37 char *fnames[] = {"name", "rank", "serial"};
44 /*----------------------------------------------------------*/
48 /*----------------------------------------------------------*/
50 DATABASE db; /* this is the database */
52 int rc; /* return code from */
57 OPERATION ops[MAX_OPS];
58 int next_op=0; /* next op to use */
61 /*----------------------------------------------------------*/
63 /* EXECUTION BEGINS HERE
65 /* Make sure the command line specifies the name
66 /* of the host on which the server program is running.
68 /*----------------------------------------------------------*/
74 fprintf(stderr, "tcl <database-name@host> <query>\n");
78 /*----------------------------------------------------------*/
80 /* Initialize the GDB library.
82 /*----------------------------------------------------------*/
86 /*----------------------------------------------------------*/
88 /* Create all the operations
90 /*----------------------------------------------------------*/
91 for (i=0; i<MAX_OPS; i++)
92 ops[i] = create_operation();
94 /*----------------------------------------------------------*/
96 /* Try for a connection to the server on the
99 /*----------------------------------------------------------*/
101 printf("Attempting database: %s\n", argv[1]);
103 if (rc = access_db(argv[1], &db) != DB_OPEN) {
104 fprintf(stderr,"Return code from access_db is %d\n",rc);
109 fprintf(stderr,"Got null db after access_db reported success\n");
113 /*----------------------------------------------------------*/
115 /* Try destroying and creating a table
117 /*----------------------------------------------------------*/
119 printf("Now queueing operations\n");
121 rc = start_performing_db_operation(ops[next_op++],db, "destroy tdbcl");
123 rc = start_performing_db_operation(ops[next_op++],db, "create tdbcl (name=c8, rank = i4, serial=i4)");
125 /*----------------------------------------------------------*/
127 /* Append some data to the table
129 /*----------------------------------------------------------*/
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)");
148 /*----------------------------------------------------------*/
150 /* Complete the operations and print the return codes
153 /*----------------------------------------------------------*/
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]),
161 /*----------------------------------------------------------*/
165 /*----------------------------------------------------------*/
167 tpd = create_tuple_descriptor(3, fnames, ftypes);
169 rel = create_relation(tpd);
171 rc = db_query(db, rel, /*argv[2]*/ "(>*name*<=tdbcl.name, >*serial*<=tdbcl.serial) where tdbcl.serial>200");
173 printf("return code from query is %d\n",rc);
175 print_relation("Query result", rel);
177 delete_relation(rel);
178 rel = create_relation(tpd);
180 rc = db_query(db, rel, /*argv[2]*/ "(>*name*<=tdbcl.name, >*serial*<=tdbcl.serial) where tdbcl.serial>200");
182 printf("return code from query is %d\n",rc);
184 print_relation("Query result", rel);
186 delete_relation(rel);
187 delete_tuple_descriptor(tpd);