]> andersk Git - moira.git/blame - server/qrtn.qc
Don't update the database on retrieves (Used to keep stats)
[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;
7536027d 194 } else {
83526631 195 status = (*v->post_rtn)(q, Argv, cl, action, actarg);
7536027d 196 }
197
d26cae4e 198 break;
199
faad6f39 200 case UPDATE:
7536027d 201 /* see if row already exists */
202 if (v->field) {
203 status = validate_row(q, Argv, v);
204 if (status != SMS_EXISTS) break;
205 }
206
207 /* build "where" clause and perform update */
cc1231a1 208 /* if q->rvar = NULL, perform post_rtn only */
209 if (q->rvar) {
7536027d 210 build_qual(q->qual, q->argc, Argv, qual);
211 status = do_update(q, &Argv[q->argc], qual, action, actarg);
212 if (status != SMS_SUCCESS) break;
cc1231a1 213 table = q->rtable;
37e49d47 214 if (strcmp(q->shortname, "sshi") && strcmp(q->shortname, "ssif")) {
215## repeat replace tblstats (updates = tblstats.updates + 1,
216## modtime = "now")
217## where tblstats.#table = @table
218 }
d26cae4e 219 }
7536027d 220
221 /* execute followup routine (if any) */
83526631 222 if (v->post_rtn) status = (*v->post_rtn)(q, Argv, cl);
7536027d 223
d26cae4e 224 break;
97479f6f 225
faad6f39 226 case APPEND:
7536027d 227 /* see if row already exists */
228 if (v->field) {
229 status = validate_row(q, Argv, v);
230 if (status != SMS_NO_MATCH) break;
d26cae4e 231 }
7536027d 232
233 /* increment id number if necessary */
d353058b 234 if (v->object_id) {
83526631 235 status = set_next_object_id(v->object_id, q->rtable);
d353058b 236 if (status != SMS_SUCCESS) break;
237 }
7536027d 238
cc1231a1 239 /* build "where" clause if needed */
240 if (q->qual) {
241 build_qual(q->qual, q->argc, Argv, qual);
242 pqual = qual;
243 } else {
244 pqual = 0;
245 }
246
7536027d 247 /* perform the append */
cc1231a1 248 /* if q->rvar = NULL, perform post_rtn only */
249 if (q->rvar) {
250 status = do_append(q, &Argv[q->argc], pqual, action, actarg);
7536027d 251 if (status != SMS_SUCCESS) break;
cc1231a1 252 table = q->rtable;
7536027d 253## repeat replace tblstats (appends = tblstats.appends + 1,
254## modtime = "now")
255## where tblstats.#table = @table
256 }
257
258 /* execute followup routine */
83526631 259 if (v->post_rtn) status = (*v->post_rtn)(q, Argv, cl);
d26cae4e 260 break;
97479f6f 261
faad6f39 262 case DELETE:
7536027d 263 /* see if row already exists */
264 if (v->field) {
265 status = validate_row(q, Argv, v);
266 if (status != SMS_EXISTS) break;
267 }
268
269 /* build "where" clause and perform delete */
cc1231a1 270 /* if q->rvar = NULL, perform post_rtn only */
271 if (q->rvar) {
7536027d 272 build_qual(q->qual, q->argc, Argv, qual);
273 status = do_delete(q, qual, action, actarg);
274 if (status != SMS_SUCCESS) break;
cc1231a1 275 table = q->rtable;
7536027d 276## repeat replace tblstats (deletes = tblstats.deletes + 1,
277## modtime = "now")
278## where tblstats.#table = @table
97479f6f 279 }
7536027d 280
281 /* execute followup routine */
83526631 282 if (v->post_rtn) status = (*v->post_rtn)(q, Argv, cl);
d26cae4e 283 break;
7536027d 284
d26cae4e 285 }
7536027d 286
d353058b 287out:
3df9e21e 288 if (q->type != RETRIEVE) {
289 if (status == SMS_SUCCESS) {
d353058b 290## end transaction /* commit to this */
83526631 291 if (journal) {
292 char buf[1024], *bp;
293 int i;
294 extern time_t now;
295
296 fprintf(journal, "%% %s %s %s",
297 cl->clname, cl->entity, ctime(&now));
298 fprintf(journal, "%s[%d] ", q->name, cl->args->sms_version_no);
299 for (i = 0; i < argc; i++) {
300 if (i != 0) {
301 putc(' ', journal);
302 }
303 requote(buf, argv_ro[i], sizeof(buf));
304 fputs(buf, journal);
305 }
306 putc('\n', journal);
307 fflush(journal);
308 }
3df9e21e 309 } else {
d353058b 310## abort /* it never happened */
3df9e21e 311 }
312 }
7536027d 313
1bf7f927 314 if (status != SMS_SUCCESS && log_flags & LOG_RES)
315 com_err(whoami, status, " (Query failed)");
7536027d 316 return(status);
97479f6f 317}
318
319build_qual(fmt, argc, argv, qual)
320 char *fmt;
321 int argc;
322 char *argv[];
323 char *qual;
324{
7536027d 325 register char *c;
326 register int i;
327 char *args[4];
83526631 328 char *index();
7536027d 329
330 c = fmt;
331 for (i = 0; i < argc; i++) {
83526631 332 c = index(c, '%');
7536027d 333 if (c++ == (char *)0) return(SMS_ARGS);
334 if (*c == 's')
335 args[i] = argv[i];
336 else if (*c == 'd')
337 *(int *)&args[i] = *(int *)argv[i]; /* sigh */
338 else
339 return(SMS_INGRES_ERR);
340 }
341
d26cae4e 342 switch (argc) {
343 case 0:
344 strcpy(qual, fmt);
345 break;
346
347 case 1:
7536027d 348 sprintf(qual, fmt, args[0]);
d26cae4e 349 break;
350
351 case 2:
7536027d 352 sprintf(qual, fmt, args[0], args[1]);
d26cae4e 353 break;
354
355 case 3:
7536027d 356 sprintf(qual, fmt, args[0], args[1], args[2]);
d26cae4e 357 break;
358
359 case 4:
7536027d 360 sprintf(qual, fmt, args[0], args[1], args[2], args[3]);
d26cae4e 361 break;
362 }
83526631 363 return(SMS_SUCCESS);
97479f6f 364}
365
cc1231a1 366char *
367build_sort(v, sort)
368 register struct validate *v;
369 char *sort;
370{
371 register struct valobj *vo;
372 register int n;
373 char elem[16];
374
375 n = v->objcnt;
376 vo = v->valobj;
377 *sort = 0;
378
379 while (--n >= 0) {
380 if (vo->type == V_SORT) {
381 sprintf(elem, "RET_VAR%d", vo->index + 1);
382 if (*sort) strcat(sort, ", ");
383 strcat(sort, elem);
384 }
385 vo++;
386 }
387
388 return ((*sort) ? sort : 0);
389}
390
9969e1bc 391
392/* Build arguement vector, verify query and arguments */
393
394sms_verify_query(cl, q, argc, argv_ro)
395 client *cl;
396 struct query *q;
397 int argc;
398 char *argv_ro[];
399{
400 register int argreq;
401 register int status;
402 register struct validate *v = q->validate;
403 register int i;
404 register int privileged = 0;
405
406 /* copy the arguments into a local argv that we can modify */
407 for (i = 0; i < argc; i++) {
408 if (strlen(argv_ro[i]) < ARGLEN)
409 strcpy(Argv[i], argv_ro[i]);
410 else
411 return(SMS_ARG_TOO_LONG);
412 }
413
414 /* check initial query access */
415 status = check_query_access(q, Argv, cl);
416 if (status != SMS_SUCCESS && status != SMS_PERM)
417 return(status);
418 if (status == SMS_SUCCESS)
419 privileged++;
420
421 /* check argument count */
422 argreq = q->argc;
423 if (q->type == UPDATE || q->type == APPEND) argreq += q->vcnt;
424 if (argc != argreq) return(SMS_ARGS);
425
426 /* validate arguments */
427 if (v && v->valobj) {
428 status = validate_fields(q, Argv, v->valobj, v->objcnt);
429 if (status != SMS_SUCCESS) return(status);
430 }
431
432 /* perform special query access check */
433 if (!privileged && v && v->acs_rtn) {
434 status = (*v->acs_rtn)(q, Argv, cl);
435 if (status != SMS_SUCCESS && status != SMS_PERM)
436 return(status);
437 if (status == SMS_SUCCESS)
438 privileged++;
439 }
440
441 return(privileged ? SMS_SUCCESS : SMS_PERM);
442}
443
7536027d 444check_query_access(q, argv, cl)
445 struct query *q;
446 char *argv[];
447 client *cl;
d26cae4e 448##{
7536027d 449## char *name;
450## int acl_id;
451## int exists;
d26cae4e 452## int rowcount;
cc1231a1 453## int errorno;
7536027d 454## static int def_uid;
455 int status;
456 int client_id;
457 char *client_type;
458
459 /* get query access control list */
460 name = q->shortname;
461## repeat retrieve (acl_id = capacls.list_id) where capacls.tag = @name
cc1231a1 462## inquire_equel (rowcount = "rowcount", errorno = "errorno")
463 if (errorno != 0) return(SMS_INGRES_ERR);
7536027d 464 if (rowcount == 0) return(SMS_PERM);
d26cae4e 465
7536027d 466 /* initialize default uid */
467 if (def_uid == 0) {
468## retrieve (def_uid = users.users_id) where users.login = "default"
d26cae4e 469 }
97479f6f 470
7536027d 471 /* check for default access */
472## range of m is members
473## repeat retrieve (exists = any(m.#member_id where m.list_id = @acl_id and
474## m.member_type = "USER" and m.#member_id = def_uid))
475 if (exists) return(SMS_SUCCESS);
476
477 /* parse client name */
478 status = get_client(cl, &client_type, &client_id);
479 if (status != SMS_SUCCESS) return(status);
480
7536027d 481 /* see if client is in the list (or any of its sub-lists) */
83526631 482 exists = find_member("LIST", acl_id, client_type, client_id, 0);
7536027d 483 return ((exists) ? SMS_SUCCESS : SMS_PERM);
484##}
97479f6f 485
7536027d 486get_client(cl, client_type, client_id)
487 client *cl;
488 char **client_type;
489 int *client_id;
490##{
491 struct krbname *krb;
492## int member_id;
493## char *name;
494## int rowcount;
495
6ec81cbf 496 if (cl->clname == NULL)
497 return SMS_PERM;
498
19bf23eb 499 /* for now ignore instances */
7536027d 500 krb = &cl->kname;
7536027d 501
502 /* if client is from local realm, get users_id */
503 if (!strcmp(krb->realm, krb_realm)) {
83526631 504 *client_id = cl->users_id;
7536027d 505 *client_type = "USER";
83526631 506 return(SMS_SUCCESS);
7536027d 507 }
83526631 508
509 /* otherwise use string_id */
510 name = cl->clname;
511## repeat retrieve (member_id = strings.string_id)
512## where strings.string = @name
7536027d 513
514 /* make sure we found a users or string id */
d26cae4e 515## inquire_equel (rowcount = "rowcount")
7536027d 516 if (rowcount == 0) return(SMS_PERM);
517
83526631 518 *client_type = "STRING";
7536027d 519 *client_id = member_id;
520 return(SMS_SUCCESS);
521##}
97479f6f 522
83526631 523##find_member(list_type, list_id, member_type, member_id, sq)
524 char *list_type;
7536027d 525## int list_id;
526## char *member_type;
527## int member_id;
528 struct save_queue *sq;
529##{
530## int exists;
531## int sublist;
532 int child;
533 struct save_queue *sq_create();
534
535 /* see if client is a direct member of list */
536## repeat retrieve (exists = any(m.#member_id where
537## m.#list_id = @list_id and
538## m.#member_type = @member_type and
539## m.#member_id = @member_id))
540 if (exists) return(1);
541
542 /* are there any sub-lists? */
7536027d 543## repeat retrieve (exists = any(m.#member_id where m.#list_id = @list_id and
544## m.#member_type = "LIST"))
545 if (!exists) return(0);
546
547 /* yes; now recurse through sublists */
548
549 /* create a save queue */
550 if (sq == (struct save_queue *)0) {
551 sq = sq_create();
552 child = 0;
553 } else {
554 child = 1;
d26cae4e 555 }
97479f6f 556
7536027d 557 /* save all sublist ids */
558## range of m is members
559## retrieve (sublist = m.#member_id)
560## where m.#list_id = list_id and m.#member_type = "LIST"
561## {
562 sq_save_unique_data(sq, sublist);
563## }
564
83526631 565 if (child) return(0);
7536027d 566
7536027d 567 /* at top-level, check sub-lists for client (breadth-first search) */
568 while (sq_get_data(sq, &sublist)) {
83526631 569 exists = find_member(list_type, sublist, member_type, member_id, sq);
7536027d 570 if (exists) {
571 sq_destroy(sq);
572 return(1);
573 }
574 }
83526631 575 sq_destroy(sq);
576 return(0);
d26cae4e 577##}
97479f6f 578
83526631 579
cc1231a1 580do_retrieve(q, pqual, psort, action, actarg)
d26cae4e 581 register struct query *q;
cc1231a1 582 char *pqual;
583 char *psort;
d26cae4e 584 int (*action)();
585 char *actarg;
586##{
587## char *rvar;
588## char *rtable;
589## char *cqual;
cc1231a1 590## char *csort;
d26cae4e 591## int rowcount;
cc1231a1 592## int errorno;
83526631 593 static char **vaddrs = (char **)NULL;
594
595 if (!vaddrs) {
596 register int i;
597
598 if ((vaddrs = (char **)malloc(sizeof(char *) * QMAXARGS)) == NULL) {
599 com_err(whoami, SMS_NO_MEM, "setting up static argv");
600 exit(1);
601 }
602 for (i = 0; i < QMAXARGS; i++) {
603 if ((vaddrs[i] = malloc(QMAXARGSIZE)) == NULL) {
604 com_err(whoami, SMS_NO_MEM, "setting up static argv");
605 exit(1);
606 }
607 }
608 }
7536027d 609
d26cae4e 610 if (q->rvar) {
611 rvar = q->rvar;
612 rtable = q->rtable;
613## range of rvar is rtable
614 }
97479f6f 615
cc1231a1 616 if (psort) {
617 csort = psort;
618 if (pqual) {
619 cqual = pqual;
83526631 620## retrieve unique (param (q->tlist, vaddrs)) where cqual
cc1231a1 621## sort by csort
622## {
83526631 623 (*action)(q->vcnt, vaddrs, actarg);
cc1231a1 624## }
625 } else {
83526631 626## retrieve unique (param (q->tlist, vaddrs))
cc1231a1 627## sort by csort
628## {
83526631 629 (*action)(q->vcnt, vaddrs, actarg);
cc1231a1 630## }
631 }
632
7536027d 633 } else {
cc1231a1 634 if (pqual) {
635 cqual = pqual;
83526631 636## retrieve unique (param (q->tlist, vaddrs)) where cqual
cc1231a1 637## {
83526631 638 (*action)(q->vcnt, vaddrs, actarg);
cc1231a1 639## }
640 } else {
83526631 641## retrieve unique (param (q->tlist, vaddrs))
cc1231a1 642## {
83526631 643 (*action)(q->vcnt, vaddrs, actarg);
cc1231a1 644## }
645 }
7536027d 646 }
97479f6f 647
cc1231a1 648## inquire_equel (rowcount = "rowcount", errorno = "errorno")
649 if (errorno != 0) return(SMS_INGRES_ERR);
7536027d 650 return ((rowcount == 0) ? SMS_NO_MATCH : SMS_SUCCESS);
d26cae4e 651##}
97479f6f 652
e38c941b 653do_update(q, argv, qual, action, actarg)
d26cae4e 654 register struct query *q;
655 char *argv[];
656 char *qual;
657 int (*action)();
658 char *actarg;
659##{
660## char *rvar;
661## char *rtable;
662## char *cqual;
cc1231a1 663## int errorno;
97479f6f 664
d26cae4e 665 rvar = q->rvar;
666 rtable = q->rtable;
667## range of rvar is rtable
97479f6f 668
d26cae4e 669 cqual = qual;
670## replace rvar (param (q->tlist, argv))
671## where cqual
97479f6f 672
cc1231a1 673## inquire_equel (errorno = "errorno")
4a7b7001 674 if (errorno == INGRES_BAD_INT)
8fcb440e 675 return(SMS_INTEGER);
676 else if (errorno != 0)
677 return(SMS_INGRES_ERR);
7536027d 678 return(SMS_SUCCESS);
d26cae4e 679##}
97479f6f 680
cc1231a1 681do_append(q, argv, pqual, action, actarg)
d26cae4e 682 register struct query *q;
683 char *argv[];
cc1231a1 684 char *pqual;
d26cae4e 685 int (*action)();
686 char *actarg;
687##{
688## char *rvar;
689## char *rtable;
7536027d 690## char *cqual;
cc1231a1 691## int errorno;
97479f6f 692
d26cae4e 693 rvar = q->rvar;
694 rtable = q->rtable;
695## range of rvar is rtable
97479f6f 696
cc1231a1 697 if (pqual) {
698 cqual = pqual;
7536027d 699## append to rtable (param (q->tlist, argv)) where cqual
700 } else {
701## append to rtable (param (q->tlist, argv))
702 }
97479f6f 703
cc1231a1 704## inquire_equel (errorno = "errorno")
8fcb440e 705 if (errorno == INGRES_BAD_INT)
706 return(SMS_INTEGER);
707 else if (errorno != 0)
708 return(SMS_INGRES_ERR);
7536027d 709 return(SMS_SUCCESS);
d26cae4e 710##}
97479f6f 711
e38c941b 712do_delete(q, qual, action, actarg)
d26cae4e 713 register struct query *q;
714 char *qual;
715 int (*action)();
716 char *actarg;
717##{
718## char *rvar;
719## char *rtable;
720## char *cqual;
cc1231a1 721## int errorno;
97479f6f 722
d26cae4e 723 rvar = q->rvar;
724 rtable = q->rtable;
725## range of rvar is rtable
97479f6f 726
d26cae4e 727 cqual = qual;
728## delete rvar where cqual
97479f6f 729
cc1231a1 730## inquire_equel (errorno = "errorno")
731 if (errorno != 0) return(SMS_INGRES_ERR);
7536027d 732 return(SMS_SUCCESS);
d26cae4e 733##}
97479f6f 734
d26cae4e 735
83526631 736/**
737 ** set_next_object_id - set next object id in values table
738 **
739 ** Inputs: object - object name in values table and in objects
740 ** table - name of table objects are found in
741 **
742 ** - called before an APPEND operation to set the next object id to
743 ** be used for the new record to the next free value
744 **
745 **/
746
747set_next_object_id(object, table)
748 char *object;
749 char *table;
750##{
751## char *name, *tbl;
752## int rowcount, exists, value;
753
754 name = object;
755 tbl = table;
756## range of v is values
757## repeat retrieve (value = v.#value) where v.#name = @name
758## inquire_equel(rowcount = "rowcount")
759 if (rowcount != 1)
8fcb440e 760 return(SMS_NO_ID);
83526631 761
762## retrieve (exists = any(tbl.name where tbl.name = value))
763## inquire_equel(rowcount = "rowcount")
764 if (rowcount != 1)
8fcb440e 765 return(SMS_NO_ID);
83526631 766 while (exists) {
767 value++;
8fcb440e 768 if (value > MAX_ID_VALUE)
769 value = MIN_ID_VALUE;
83526631 770## retrieve (exists = any(tbl.name where tbl.name = value))
771 }
772
773 if (LOG_RES)
774 com_err(whoami, 0, "setting ID %s to %d", name, value);
775## repeat replace v (#value = @value) where v.#name = @name
776 return(SMS_SUCCESS);
777##}
778
779
780/* For now this just checks the argc's. It should also see that there
781 * are no duplicate names.
782 */
783
784sanity_check_queries()
785{
786 register int i;
787 int maxv = 0, maxa = 0;
788 extern int QueryCount1, QueryCount2;
789 extern struct query Queries1[], Queries2[];
790#define MAX(x,y) ((x) > (y) ? (x) : (y))
791
792 for (i = 0; i < QueryCount1; i++) {
793 maxv = MAX(maxv, Queries1[i].vcnt);
794 maxa = MAX(maxa, Queries1[i].argc);
795 }
796 for (i = 0; i < QueryCount2; i++) {
797 maxv = MAX(maxv, Queries2[i].vcnt);
798 maxa = MAX(maxa, Queries2[i].argc);
799 }
800 if (MAX(maxv, maxa) > QMAXARGS) {
801 com_err(whoami, 0, "A query has more args than QMAXARGS");
802 exit(1);
803 }
804}
805
806
d26cae4e 807/*
808 * Local Variables:
809 * mode: c
810 * c-indent-level: 4
811 * c-continued-statement-offset: 4
812 * c-brace-offset: -4
813 * c-argdecl-indent: 4
814 * c-label-offset: -4
815 * End:
816 */
817
This page took 0.179894 seconds and 5 git commands to generate.