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