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