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