]> andersk Git - moira.git/blame - server/qrtn.qc
made clname & entity buffers instead of pointers;
[moira.git] / server / qrtn.qc
CommitLineData
d26cae4e 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
83526631 6 * Copyright (C) 1987, 1988 by the Massachusetts Institute of Technology
7ee33a8d 7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
faad6f39 9 *
d26cae4e 10 */
11
12#ifndef lint
13static char *rcsid_qrtn_qc = "$Header$";
14#endif lint
15
7ee33a8d 16#include <mit-copyright.h>
97479f6f 17#include "query.h"
97479f6f 18#include "sms_server.h"
19
20char *Argv[16];
21
ca7c2f3d 22int ingres_errno = 0;
23int sms_errcode = 0;
24## int query_timeout = 30;
7536027d 25extern char *whoami;
83526631 26extern FILE *journal;
97479f6f 27
8fcb440e 28#define INGRES_BAD_INT 4111
29#define INGRES_BAD_DATE 4302
4a7b7001 30#define INGRES_DEADLOCK 4700
ca7c2f3d 31#define INGRES_TIMEOUT 4702
8fcb440e 32
d26cae4e 33/*
34 * ingerr: (supposedly) called when Ingres indicates an error.
35 * I have not yet been able to get this to work to intercept a
36 * database open error.
37 */
38
39static int ingerr(num)
40 int *num;
97479f6f 41{
ca7c2f3d 42 ingres_errno = *num;
8fcb440e 43
44 switch (*num) {
45 case INGRES_BAD_INT:
ca7c2f3d 46 sms_errcode = SMS_INTEGER;
8fcb440e 47 break;
48 case INGRES_BAD_DATE:
ca7c2f3d 49 sms_errcode = SMS_DATE;
8fcb440e 50 break;
4a7b7001 51 case INGRES_DEADLOCK:
ca7c2f3d 52 sms_errcode = SMS_DEADLOCK;
7ee33a8d 53 com_err(whoami, 0, "INGRES deadlock detected");
ca7c2f3d 54 break;
55 case INGRES_TIMEOUT:
56 sms_errcode = SMS_BUSY;
57 com_err(whoami, 0, "timed out getting lock");
4a7b7001 58 break;
8fcb440e 59 default:
ca7c2f3d 60 sms_errcode = SMS_INGRES_ERR;
8fcb440e 61 com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num);
0a7ae10e 62 critical_alert("SMS", "SMS server encountered INGRES ERROR %d", *num);
8fcb440e 63 return (*num);
64 }
65 return (0);
97479f6f 66}
67
d26cae4e 68int sms_open_database()
97479f6f 69{
d26cae4e 70 register int i;
83526631 71 char *malloc();
97479f6f 72
d26cae4e 73 /* initialize local argv */
74 for (i = 0; i < 16; i++)
83526631 75 Argv[i] = malloc(ARGLEN);
97479f6f 76
d26cae4e 77 IIseterr(ingerr);
97479f6f 78
d26cae4e 79 ingres_errno = 0;
97479f6f 80
d26cae4e 81 /* open the database */
82## ingres sms
ca7c2f3d 83## set lockmode session where level = table, timeout = query_timeout
45266a6f 84## set lockmode on capacls where readlock = shared
85## set lockmode on alias where readlock = shared
d26cae4e 86 return ingres_errno;
97479f6f 87}
88
d26cae4e 89int sms_close_database()
97479f6f 90{
d26cae4e 91## exit
97479f6f 92}
93
7536027d 94sms_check_access(cl, name, argc, argv_ro)
95 client *cl;
96 char *name;
97 int argc;
98 char *argv_ro[];
99{
9969e1bc 100 struct query *q;
7536027d 101 struct query *get_query_by_name();
7536027d 102
ca7c2f3d 103 ingres_errno = 0;
104
83526631 105 q = get_query_by_name(name, cl->args->sms_version_no);
9969e1bc 106 if (q == (struct query *)0)
107 return(SMS_NO_HANDLE);
7536027d 108
9969e1bc 109 return(sms_verify_query(cl, q, argc, argv_ro));
7536027d 110}
111
112sms_process_query(cl, name, argc, argv_ro, action, actarg)
113 client *cl;
d26cae4e 114 char *name;
115 int argc;
116 char *argv_ro[];
117 int (*action)();
118 char *actarg;
97479f6f 119{
d26cae4e 120 register struct query *q;
7536027d 121 register int status;
7536027d 122 register struct validate *v;
7536027d 123 char qual[256];
cc1231a1 124 char sort[32];
7536027d 125 char *pqual;
cc1231a1 126 char *psort;
7536027d 127## char *table;
128 struct save_queue *sq;
d26cae4e 129 struct query *get_query_by_name();
7536027d 130 int sq_save_args();
131 struct save_queue *sq_create();
cc1231a1 132 char *build_sort();
d26cae4e 133
ca7c2f3d 134 ingres_errno = 0;
135
7536027d 136 /* list queries command */
137 if (!strcmp(name, "_list_queries")) {
83526631 138 list_queries(cl->args->sms_version_no, action, actarg);
7536027d 139 return(SMS_SUCCESS);
140 }
141
142 /* help query command */
143 if (!strcmp(name, "_help")) {
83526631 144 if (argc < 1)
145 return(SMS_ARGS);
146 q = get_query_by_name(argv_ro[0], cl->args->sms_version_no);
7536027d 147 if (q == (struct query *)0) return(SMS_NO_HANDLE);
148 help_query(q, action, actarg);
149 return(SMS_SUCCESS);
150 }
151
152 /* get query structure, return error if named query does not exist */
83526631 153 q = get_query_by_name(name, cl->args->sms_version_no);
7536027d 154 if (q == (struct query *)0) return(SMS_NO_HANDLE);
155 v = q->validate;
156
7ee33a8d 157 if (q->type != RETRIEVE) {
158## set lockmode session where readlock = exclusive
d353058b 159## begin transaction
7ee33a8d 160 }
d353058b 161
9969e1bc 162 /* setup argument vector, verify access and arguments */
163 if ((status = sms_verify_query(cl, q, argc, argv_ro)) != SMS_SUCCESS)
d353058b 164 goto out;
7536027d 165
166 /* perform any special query pre-processing */
167 if (v && v->pre_rtn) {
168 status = (*v->pre_rtn)(q, Argv, cl, 0);
9969e1bc 169 if (status != SMS_SUCCESS)
d353058b 170 goto out;
7536027d 171 }
172
d26cae4e 173 switch (q->type) {
faad6f39 174 case RETRIEVE:
7536027d 175 /* for queries that do not permit wildcarding, check if row
176 uniquely exists */
177 if (v && v->field) {
178 status = validate_row(q, Argv, v);
179 if (status != SMS_EXISTS) break;
180 }
181
182 /* build "where" clause if needed */
d26cae4e 183 if (q->qual) {
184 build_qual(q->qual, q->argc, Argv, qual);
7536027d 185 pqual = qual;
186 } else {
187 pqual = 0;
188 }
189
cc1231a1 190 /* build "sort" clause if needed */
191 if (v && v->valobj) {
192 psort = build_sort(v, sort);
193 } else {
194 psort = 0;
195 }
196
7536027d 197 /* if there is a followup routine, then we must save the results */
198 /* of the first query for use by the followup routine */
cc1231a1 199 /* if q->rvar = NULL, perform post_rtn only */
200 if (q->rvar) {
7536027d 201 if (v && v->post_rtn) {
202 sq = sq_create();
cc1231a1 203 status = do_retrieve(q, pqual, psort, sq_save_args, sq);
7536027d 204 if (status != SMS_SUCCESS) {
205 sq_destroy(sq);
206 break;
207 }
83526631 208 status = (*v->post_rtn)(q, sq, v, action, actarg, cl);
7536027d 209 } else {
210 /* normal retrieve */
cc1231a1 211 status = do_retrieve(q, pqual, psort, action, actarg);
7536027d 212 }
213 if (status != SMS_SUCCESS) break;
7536027d 214 } else {
83526631 215 status = (*v->post_rtn)(q, Argv, cl, action, actarg);
7536027d 216 }
217
d26cae4e 218 break;
219
faad6f39 220 case UPDATE:
7536027d 221 /* see if row already exists */
222 if (v->field) {
223 status = validate_row(q, Argv, v);
224 if (status != SMS_EXISTS) break;
225 }
226
227 /* build "where" clause and perform update */
cc1231a1 228 /* if q->rvar = NULL, perform post_rtn only */
229 if (q->rvar) {
7536027d 230 build_qual(q->qual, q->argc, Argv, qual);
231 status = do_update(q, &Argv[q->argc], qual, action, actarg);
232 if (status != SMS_SUCCESS) break;
cc1231a1 233 table = q->rtable;
37e49d47 234 if (strcmp(q->shortname, "sshi") && strcmp(q->shortname, "ssif")) {
235## repeat replace tblstats (updates = tblstats.updates + 1,
236## modtime = "now")
237## where tblstats.#table = @table
238 }
d26cae4e 239 }
7536027d 240
241 /* execute followup routine (if any) */
83526631 242 if (v->post_rtn) status = (*v->post_rtn)(q, Argv, cl);
7536027d 243
d26cae4e 244 break;
97479f6f 245
faad6f39 246 case APPEND:
7536027d 247 /* see if row already exists */
248 if (v->field) {
249 status = validate_row(q, Argv, v);
250 if (status != SMS_NO_MATCH) break;
d26cae4e 251 }
7536027d 252
253 /* increment id number if necessary */
d353058b 254 if (v->object_id) {
83526631 255 status = set_next_object_id(v->object_id, q->rtable);
d353058b 256 if (status != SMS_SUCCESS) break;
257 }
7536027d 258
cc1231a1 259 /* build "where" clause if needed */
260 if (q->qual) {
261 build_qual(q->qual, q->argc, Argv, qual);
262 pqual = qual;
263 } else {
264 pqual = 0;
265 }
266
7536027d 267 /* perform the append */
cc1231a1 268 /* if q->rvar = NULL, perform post_rtn only */
269 if (q->rvar) {
270 status = do_append(q, &Argv[q->argc], pqual, action, actarg);
7536027d 271 if (status != SMS_SUCCESS) break;
cc1231a1 272 table = q->rtable;
7536027d 273## repeat replace tblstats (appends = tblstats.appends + 1,
274## modtime = "now")
275## where tblstats.#table = @table
276 }
277
278 /* execute followup routine */
83526631 279 if (v->post_rtn) status = (*v->post_rtn)(q, Argv, cl);
d26cae4e 280 break;
97479f6f 281
faad6f39 282 case DELETE:
7536027d 283 /* see if row already exists */
284 if (v->field) {
285 status = validate_row(q, Argv, v);
286 if (status != SMS_EXISTS) break;
287 }
288
289 /* build "where" clause and perform delete */
cc1231a1 290 /* if q->rvar = NULL, perform post_rtn only */
291 if (q->rvar) {
7536027d 292 build_qual(q->qual, q->argc, Argv, qual);
293 status = do_delete(q, qual, action, actarg);
294 if (status != SMS_SUCCESS) break;
cc1231a1 295 table = q->rtable;
7536027d 296## repeat replace tblstats (deletes = tblstats.deletes + 1,
297## modtime = "now")
298## where tblstats.#table = @table
97479f6f 299 }
7536027d 300
301 /* execute followup routine */
83526631 302 if (v->post_rtn) status = (*v->post_rtn)(q, Argv, cl);
d26cae4e 303 break;
7536027d 304
d26cae4e 305 }
7536027d 306
d353058b 307out:
3df9e21e 308 if (q->type != RETRIEVE) {
309 if (status == SMS_SUCCESS) {
d353058b 310## end transaction /* commit to this */
83526631 311 if (journal) {
312 char buf[1024], *bp;
313 int i;
314 extern time_t now;
315
316 fprintf(journal, "%% %s %s %s",
317 cl->clname, cl->entity, ctime(&now));
318 fprintf(journal, "%s[%d] ", q->name, cl->args->sms_version_no);
319 for (i = 0; i < argc; i++) {
320 if (i != 0) {
321 putc(' ', journal);
322 }
323 requote(buf, argv_ro[i], sizeof(buf));
324 fputs(buf, journal);
325 }
326 putc('\n', journal);
327 fflush(journal);
328 }
3df9e21e 329 } else {
ca7c2f3d 330 if (ingres_errno != INGRES_DEADLOCK) {
7ee33a8d 331## abort /* it never happened */
332 }
3df9e21e 333 }
ca7c2f3d 334## set lockmode session where readlock = system
335 }
336
337 if (status == SMS_SUCCESS && ingres_errno != 0) {
338 critical_alert("SMS", "Server didn't notice INGRES ERROR %d",
339 ingres_errno);
340 status = SMS_INTERNAL;
3df9e21e 341 }
7536027d 342
1bf7f927 343 if (status != SMS_SUCCESS && log_flags & LOG_RES)
344 com_err(whoami, status, " (Query failed)");
ca7c2f3d 345 /* until all the clients know about SMS_BUSY, convert this error
346 * to one they will recognize.
347 */
348 if (status == SMS_BUSY)
349 status = SMS_DEADLOCK;
7536027d 350 return(status);
97479f6f 351}
352
353build_qual(fmt, argc, argv, qual)
354 char *fmt;
355 int argc;
356 char *argv[];
357 char *qual;
358{
7536027d 359 register char *c;
360 register int i;
361 char *args[4];
83526631 362 char *index();
7536027d 363
364 c = fmt;
365 for (i = 0; i < argc; i++) {
83526631 366 c = index(c, '%');
7536027d 367 if (c++ == (char *)0) return(SMS_ARGS);
368 if (*c == 's')
369 args[i] = argv[i];
370 else if (*c == 'd')
371 *(int *)&args[i] = *(int *)argv[i]; /* sigh */
372 else
373 return(SMS_INGRES_ERR);
374 }
375
d26cae4e 376 switch (argc) {
377 case 0:
378 strcpy(qual, fmt);
379 break;
380
381 case 1:
7536027d 382 sprintf(qual, fmt, args[0]);
d26cae4e 383 break;
384
385 case 2:
7536027d 386 sprintf(qual, fmt, args[0], args[1]);
d26cae4e 387 break;
388
389 case 3:
7536027d 390 sprintf(qual, fmt, args[0], args[1], args[2]);
d26cae4e 391 break;
392
393 case 4:
7536027d 394 sprintf(qual, fmt, args[0], args[1], args[2], args[3]);
d26cae4e 395 break;
396 }
83526631 397 return(SMS_SUCCESS);
97479f6f 398}
399
cc1231a1 400char *
401build_sort(v, sort)
402 register struct validate *v;
403 char *sort;
404{
405 register struct valobj *vo;
406 register int n;
407 char elem[16];
408
409 n = v->objcnt;
410 vo = v->valobj;
411 *sort = 0;
412
413 while (--n >= 0) {
414 if (vo->type == V_SORT) {
415 sprintf(elem, "RET_VAR%d", vo->index + 1);
416 if (*sort) strcat(sort, ", ");
417 strcat(sort, elem);
418 }
419 vo++;
420 }
421
422 return ((*sort) ? sort : 0);
423}
424
9969e1bc 425
426/* Build arguement vector, verify query and arguments */
427
428sms_verify_query(cl, q, argc, argv_ro)
429 client *cl;
430 struct query *q;
431 int argc;
432 char *argv_ro[];
433{
434 register int argreq;
435 register int status;
436 register struct validate *v = q->validate;
437 register int i;
438 register int privileged = 0;
02d466cf 439 int len;
9969e1bc 440
441 /* copy the arguments into a local argv that we can modify */
7ee33a8d 442 if (argc >= QMAXARGS)
443 return(SMS_ARGS);
9969e1bc 444 for (i = 0; i < argc; i++) {
02d466cf 445 if ((len = strlen(argv_ro[i])) < ARGLEN)
9969e1bc 446 strcpy(Argv[i], argv_ro[i]);
447 else
448 return(SMS_ARG_TOO_LONG);
02d466cf 449 if (Argv[i][len-1] == '\\')
450 return(SMS_BAD_CHAR);
9969e1bc 451 }
452
453 /* check initial query access */
454 status = check_query_access(q, Argv, cl);
455 if (status != SMS_SUCCESS && status != SMS_PERM)
456 return(status);
457 if (status == SMS_SUCCESS)
458 privileged++;
459
460 /* check argument count */
461 argreq = q->argc;
462 if (q->type == UPDATE || q->type == APPEND) argreq += q->vcnt;
463 if (argc != argreq) return(SMS_ARGS);
464
465 /* validate arguments */
466 if (v && v->valobj) {
467 status = validate_fields(q, Argv, v->valobj, v->objcnt);
468 if (status != SMS_SUCCESS) return(status);
469 }
470
471 /* perform special query access check */
472 if (!privileged && v && v->acs_rtn) {
473 status = (*v->acs_rtn)(q, Argv, cl);
474 if (status != SMS_SUCCESS && status != SMS_PERM)
475 return(status);
476 if (status == SMS_SUCCESS)
477 privileged++;
478 }
479
480 return(privileged ? SMS_SUCCESS : SMS_PERM);
481}
482
7536027d 483check_query_access(q, argv, cl)
484 struct query *q;
485 char *argv[];
486 client *cl;
d26cae4e 487##{
7536027d 488## char *name;
489## int acl_id;
490## int exists;
d26cae4e 491## int rowcount;
cc1231a1 492## int errorno;
7536027d 493## static int def_uid;
494 int status;
495 int client_id;
496 char *client_type;
497
498 /* get query access control list */
499 name = q->shortname;
500## repeat retrieve (acl_id = capacls.list_id) where capacls.tag = @name
cc1231a1 501## inquire_equel (rowcount = "rowcount", errorno = "errorno")
502 if (errorno != 0) return(SMS_INGRES_ERR);
7536027d 503 if (rowcount == 0) return(SMS_PERM);
d26cae4e 504
7536027d 505 /* initialize default uid */
506 if (def_uid == 0) {
507## retrieve (def_uid = users.users_id) where users.login = "default"
d26cae4e 508 }
97479f6f 509
7536027d 510 /* check for default access */
dff355ae 511## range of m is imembers
7536027d 512## repeat retrieve (exists = any(m.#member_id where m.list_id = @acl_id and
513## m.member_type = "USER" and m.#member_id = def_uid))
514 if (exists) return(SMS_SUCCESS);
515
516 /* parse client name */
517 status = get_client(cl, &client_type, &client_id);
518 if (status != SMS_SUCCESS) return(status);
519
7536027d 520 /* see if client is in the list (or any of its sub-lists) */
83526631 521 exists = find_member("LIST", acl_id, client_type, client_id, 0);
7536027d 522 return ((exists) ? SMS_SUCCESS : SMS_PERM);
523##}
97479f6f 524
7536027d 525get_client(cl, client_type, client_id)
526 client *cl;
527 char **client_type;
528 int *client_id;
529##{
530 struct krbname *krb;
531## int member_id;
532## char *name;
533## int rowcount;
534
6ec81cbf 535 if (cl->clname == NULL)
536 return SMS_PERM;
537
19bf23eb 538 /* for now ignore instances */
7536027d 539 krb = &cl->kname;
7536027d 540
541 /* if client is from local realm, get users_id */
542 if (!strcmp(krb->realm, krb_realm)) {
83526631 543 *client_id = cl->users_id;
7536027d 544 *client_type = "USER";
83526631 545 return(SMS_SUCCESS);
7536027d 546 }
83526631 547
548 /* otherwise use string_id */
549 name = cl->clname;
550## repeat retrieve (member_id = strings.string_id)
551## where strings.string = @name
7536027d 552
553 /* make sure we found a users or string id */
d26cae4e 554## inquire_equel (rowcount = "rowcount")
7536027d 555 if (rowcount == 0) return(SMS_PERM);
556
83526631 557 *client_type = "STRING";
7536027d 558 *client_id = member_id;
559 return(SMS_SUCCESS);
560##}
97479f6f 561
dff355ae 562##find_member(list_type, list_id, member_type, member_id)
83526631 563 char *list_type;
7536027d 564## int list_id;
565## char *member_type;
566## int member_id;
7536027d 567##{
dff355ae 568## int exists, errorno;
7536027d 569
e45a151a 570 if (!strcmp(strtrim(list_type), strtrim(member_type)) &&
571 list_id == member_id)
572 return(1);
573
7536027d 574 /* see if client is a direct member of list */
dff355ae 575## range of m is imembers
7536027d 576## repeat retrieve (exists = any(m.#member_id where
577## m.#list_id = @list_id and
578## m.#member_type = @member_type and
579## m.#member_id = @member_id))
dff355ae 580## inquire_equel(errorno = "errorno")
581 if (errorno == 0)
582 return(exists);
583 else
584 return(0);
d26cae4e 585##}
97479f6f 586
83526631 587
cc1231a1 588do_retrieve(q, pqual, psort, action, actarg)
d26cae4e 589 register struct query *q;
cc1231a1 590 char *pqual;
591 char *psort;
d26cae4e 592 int (*action)();
593 char *actarg;
594##{
595## char *rvar;
596## char *rtable;
597## char *cqual;
cc1231a1 598## char *csort;
d26cae4e 599## int rowcount;
cc1231a1 600## int errorno;
83526631 601 static char **vaddrs = (char **)NULL;
602
603 if (!vaddrs) {
604 register int i;
605
606 if ((vaddrs = (char **)malloc(sizeof(char *) * QMAXARGS)) == NULL) {
607 com_err(whoami, SMS_NO_MEM, "setting up static argv");
608 exit(1);
609 }
610 for (i = 0; i < QMAXARGS; i++) {
611 if ((vaddrs[i] = malloc(QMAXARGSIZE)) == NULL) {
612 com_err(whoami, SMS_NO_MEM, "setting up static argv");
613 exit(1);
614 }
615 }
616 }
7536027d 617
d26cae4e 618 if (q->rvar) {
619 rvar = q->rvar;
620 rtable = q->rtable;
621## range of rvar is rtable
622 }
97479f6f 623
cc1231a1 624 if (psort) {
625 csort = psort;
626 if (pqual) {
627 cqual = pqual;
83526631 628## retrieve unique (param (q->tlist, vaddrs)) where cqual
cc1231a1 629## sort by csort
630## {
83526631 631 (*action)(q->vcnt, vaddrs, actarg);
cc1231a1 632## }
633 } else {
83526631 634## retrieve unique (param (q->tlist, vaddrs))
cc1231a1 635## sort by csort
636## {
83526631 637 (*action)(q->vcnt, vaddrs, actarg);
cc1231a1 638## }
639 }
640
7536027d 641 } else {
cc1231a1 642 if (pqual) {
643 cqual = pqual;
83526631 644## retrieve unique (param (q->tlist, vaddrs)) where cqual
cc1231a1 645## {
83526631 646 (*action)(q->vcnt, vaddrs, actarg);
cc1231a1 647## }
648 } else {
83526631 649## retrieve unique (param (q->tlist, vaddrs))
cc1231a1 650## {
83526631 651 (*action)(q->vcnt, vaddrs, actarg);
cc1231a1 652## }
653 }
7536027d 654 }
97479f6f 655
cc1231a1 656## inquire_equel (rowcount = "rowcount", errorno = "errorno")
657 if (errorno != 0) return(SMS_INGRES_ERR);
7536027d 658 return ((rowcount == 0) ? SMS_NO_MATCH : SMS_SUCCESS);
d26cae4e 659##}
97479f6f 660
e38c941b 661do_update(q, argv, qual, action, actarg)
d26cae4e 662 register struct query *q;
663 char *argv[];
664 char *qual;
665 int (*action)();
666 char *actarg;
667##{
668## char *rvar;
669## char *rtable;
670## char *cqual;
cc1231a1 671## int errorno;
97479f6f 672
d26cae4e 673 rvar = q->rvar;
674 rtable = q->rtable;
675## range of rvar is rtable
97479f6f 676
d26cae4e 677 cqual = qual;
678## replace rvar (param (q->tlist, argv))
679## where cqual
97479f6f 680
cc1231a1 681## inquire_equel (errorno = "errorno")
4a7b7001 682 if (errorno == INGRES_BAD_INT)
8fcb440e 683 return(SMS_INTEGER);
684 else if (errorno != 0)
685 return(SMS_INGRES_ERR);
7536027d 686 return(SMS_SUCCESS);
d26cae4e 687##}
97479f6f 688
cc1231a1 689do_append(q, argv, pqual, action, actarg)
d26cae4e 690 register struct query *q;
691 char *argv[];
cc1231a1 692 char *pqual;
d26cae4e 693 int (*action)();
694 char *actarg;
695##{
696## char *rvar;
697## char *rtable;
7536027d 698## char *cqual;
cc1231a1 699## int errorno;
97479f6f 700
d26cae4e 701 rvar = q->rvar;
702 rtable = q->rtable;
703## range of rvar is rtable
97479f6f 704
cc1231a1 705 if (pqual) {
706 cqual = pqual;
7536027d 707## append to rtable (param (q->tlist, argv)) where cqual
708 } else {
709## append to rtable (param (q->tlist, argv))
710 }
97479f6f 711
cc1231a1 712## inquire_equel (errorno = "errorno")
8fcb440e 713 if (errorno == INGRES_BAD_INT)
714 return(SMS_INTEGER);
715 else if (errorno != 0)
716 return(SMS_INGRES_ERR);
7536027d 717 return(SMS_SUCCESS);
d26cae4e 718##}
97479f6f 719
e38c941b 720do_delete(q, qual, action, actarg)
d26cae4e 721 register struct query *q;
722 char *qual;
723 int (*action)();
724 char *actarg;
725##{
726## char *rvar;
727## char *rtable;
728## char *cqual;
cc1231a1 729## int errorno;
97479f6f 730
d26cae4e 731 rvar = q->rvar;
732 rtable = q->rtable;
733## range of rvar is rtable
97479f6f 734
d26cae4e 735 cqual = qual;
736## delete rvar where cqual
97479f6f 737
cc1231a1 738## inquire_equel (errorno = "errorno")
739 if (errorno != 0) return(SMS_INGRES_ERR);
7536027d 740 return(SMS_SUCCESS);
d26cae4e 741##}
97479f6f 742
d26cae4e 743
83526631 744/**
745 ** set_next_object_id - set next object id in values table
746 **
747 ** Inputs: object - object name in values table and in objects
748 ** table - name of table objects are found in
749 **
750 ** - called before an APPEND operation to set the next object id to
751 ** be used for the new record to the next free value
752 **
753 **/
754
755set_next_object_id(object, table)
756 char *object;
757 char *table;
758##{
759## char *name, *tbl;
760## int rowcount, exists, value;
761
762 name = object;
763 tbl = table;
764## range of v is values
765## repeat retrieve (value = v.#value) where v.#name = @name
766## inquire_equel(rowcount = "rowcount")
767 if (rowcount != 1)
8fcb440e 768 return(SMS_NO_ID);
83526631 769
770## retrieve (exists = any(tbl.name where tbl.name = value))
771## inquire_equel(rowcount = "rowcount")
772 if (rowcount != 1)
8fcb440e 773 return(SMS_NO_ID);
83526631 774 while (exists) {
775 value++;
8fcb440e 776 if (value > MAX_ID_VALUE)
777 value = MIN_ID_VALUE;
83526631 778## retrieve (exists = any(tbl.name where tbl.name = value))
779 }
780
781 if (LOG_RES)
782 com_err(whoami, 0, "setting ID %s to %d", name, value);
783## repeat replace v (#value = @value) where v.#name = @name
784 return(SMS_SUCCESS);
785##}
786
787
788/* For now this just checks the argc's. It should also see that there
789 * are no duplicate names.
790 */
791
792sanity_check_queries()
793{
794 register int i;
795 int maxv = 0, maxa = 0;
c5a0c32c 796#ifdef MULTIPROTOCOLS
83526631 797 extern int QueryCount1, QueryCount2;
798 extern struct query Queries1[], Queries2[];
c5a0c32c 799#else
800 extern int QueryCount2;
801 extern struct query Queries2[];
802#endif MULTIPROTOCOLS
803
83526631 804#define MAX(x,y) ((x) > (y) ? (x) : (y))
805
c5a0c32c 806#ifdef MULTIPROTOCOLS
83526631 807 for (i = 0; i < QueryCount1; i++) {
808 maxv = MAX(maxv, Queries1[i].vcnt);
809 maxa = MAX(maxa, Queries1[i].argc);
810 }
c5a0c32c 811#endif MULTIPROTOCOLS
83526631 812 for (i = 0; i < QueryCount2; i++) {
813 maxv = MAX(maxv, Queries2[i].vcnt);
814 maxa = MAX(maxa, Queries2[i].argc);
815 }
816 if (MAX(maxv, maxa) > QMAXARGS) {
817 com_err(whoami, 0, "A query has more args than QMAXARGS");
818 exit(1);
819 }
820}
This page took 0.191821 seconds and 5 git commands to generate.