]> andersk Git - moira.git/blame - regtape/students.dc
detect deadlock errors
[moira.git] / regtape / students.dc
CommitLineData
093c49c9 1/* $Header$
2 */
3
4#include <stdio.h>
5#include <strings.h>
6#include <ctype.h>
7#include <sys/time.h>
932028de 8#include <moira.h>
9#include <moira_site.h>
8638fcf9 10EXEC SQL INCLUDE sqlca;
093c49c9 11
12
8638fcf9 13#define WHO 11859 /* root */
14#define PROG "stu-tape"
5e2b5b5f 15
397e9044 16#define MAX_ID_VALUE 31999
5e2b5b5f 17#define MIN_ID_VALUE 101
18
093c49c9 19/* File format is:
20
210-29 name
2230-38 id number
2350-54 school code
2455-79 year
2580-109 address
26110-124 room
27125-144 city
28145-158 state
29159-168 dorm phone
30169-212 home address
31213-232 home city
32243-251 mit phone (?)
33*/
34
35#define LOC_NAME 0
36#define LOC_ID 30
37#define LOC_COURSE 50
38#define LOC_YEAR 55
39#define LOC_ADDRESS 80
40#define LOC_DORM_ROOM 110
41#define LOC_CITY 125
42#define LOC_STATE 145
c48e3c93 43#define LOC_DPHONE 155
e3c8ca24 44#define LOC_MPHONE 243
093c49c9 45
e3c8ca24 46#define LEN_NAME 30
093c49c9 47#define LEN_ID 9
e3c8ca24 48#define LEN_COURSE 5
49#define LEN_YEAR 25
50#define LEN_ADDRESS 30
51#define LEN_DORM_ROOM 15
52#define LEN_CITY 20
c48e3c93 53#define LEN_STATE 10
54#define LEN_DPHONE 12
55#define LEN_MPHONE 12
093c49c9 56
57struct entry {
e3c8ca24 58 char *name;
093c49c9 59 char *last;
60 char *first;
61 char *middle;
62 char *title;
63 char *id;
64 char *eid;
65 char *course;
66 char *year;
67 char *address;
68 char *dorm;
69 char *city;
70 char *state;
71 char *dphone;
72 char *mphone;
73 char *class;
093c49c9 74};
75
76
77char *whoami;
a97bc039 78int newfinger = 0;
093c49c9 79
837b0ec6 80#define SQL_DUPLICATE -40100
e2048305 81#define SQL_DEADLOCK -49900
82#define sqlfail() (sqlca.sqlcode && sqlca.sqlcode != 100)
093c49c9 83
84main(argc, argv)
85int argc;
86char **argv;
8638fcf9 87{
093c49c9 88 FILE *in;
89 struct entry *e, *get_next_entry();
a97bc039 90 int i, wait = 0;
91 char buf[BUFSIZ], *file = NULL;
093c49c9 92
93 whoami = rindex(argv[0], '/');
94 if (whoami)
95 whoami++;
96 else
97 whoami = argv[0];
98
a97bc039 99 for (i = 1; i < argc; i++) {
100 if (!strcmp(argv[i], "-w"))
101 wait++;
102 else if (!strcmp(argv[i], "-D"))
103 setenv("ING_SET", "set printqry");
104 else if (!strcmp(argv[i], "-n"))
105 newfinger++;
106 else if (file != NULL)
dcd4e696 107 fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
a97bc039 108 else
109 file = argv[i];
110 }
093c49c9 111
a97bc039 112 in = fopen(file, "r");
093c49c9 113 if (in == NULL) {
a97bc039 114 fprintf(stderr, "Unable to open %s for input\n", file);
093c49c9 115 exit(1);
116 }
117
dcd4e696 118 setlinebuf(stdout);
119 setlinebuf(stderr);
120
8638fcf9 121 EXEC SQL CONNECT moira;
837b0ec6 122 if (sqlca.sqlcode != 0) {
123 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
124 exit(1);
125 }
5e2b5b5f 126
093c49c9 127 while (e = get_next_entry(in)) {
e2048305 128 again:
093c49c9 129 process_entry(e);
837b0ec6 130 EXEC SQL COMMIT WORK;
131 if (sqlca.sqlcode != 0) {
e2048305 132 if (sqlca.sqlcode == SQL_DEADLOCK) {
133 com_err(whoami, MR_DEADLOCK, "commiting work");
134 goto again;
135 } else {
136 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
137 exit(1);
138 }
837b0ec6 139 }
093c49c9 140 if (wait) {
141 printf("Next");
142 fflush(stdout);
143 gets(buf);
144 }
145 }
146
093c49c9 147 exit(0);
8638fcf9 148}
093c49c9 149
150
151struct entry *get_next_entry(in)
152FILE *in;
153{
154 static struct entry e;
155 static char buf[BUFSIZ], eid[16], classbuf[10], titlebuf[12];
e3c8ca24 156 static char name[LEN_NAME+1], id[LEN_ID+1], course[LEN_COURSE+1];
157 static char year[LEN_YEAR+1], address[LEN_ADDRESS+1];
158 static char dorm_room[LEN_DORM_ROOM+1], city[LEN_CITY+1];
159 static char state[LEN_STATE+1], dphone[LEN_DPHONE+1], mphone[LEN_MPHONE+1];
160 static char sname[LEN_NAME+1], title[128];
161 static int nyear = 0;
039f9637 162 int ends_jr, ends_iii, ends_iv, ends_sr, ends_ii, ends_v;
093c49c9 163 char *p;
164
e3c8ca24 165 if (nyear == 0) {
093c49c9 166 struct tm *tm;
167 struct timeval tv;
168
169 gettimeofday(&tv, NULL);
170 tm = localtime(&tv.tv_sec);
e3c8ca24 171 nyear = tm->tm_year;
093c49c9 172 if (tm->tm_mon > 5)
e3c8ca24 173 nyear++;
093c49c9 174 }
175
22a6d0dc 176 if (fgets(buf, sizeof(buf), in) == NULL)
177 return((struct entry *)NULL);
e3c8ca24 178
179 strncpy(name, &buf[LOC_NAME], LEN_NAME); name[LEN_NAME] = 0;
180 strncpy(id, &buf[LOC_ID], LEN_ID); id[LEN_ID] = 0;
181 strncpy(course, &buf[LOC_COURSE], LEN_COURSE); course[LEN_COURSE] = 0;
182 strncpy(year, &buf[LOC_YEAR], LEN_YEAR); year[LEN_YEAR] = 0;
183 strncpy(address, &buf[LOC_ADDRESS], LEN_ADDRESS); address[LEN_ADDRESS] = 0;
184 strncpy(dorm_room, &buf[LOC_DORM_ROOM], LEN_DORM_ROOM); dorm_room[LEN_DORM_ROOM] = 0;
185 strncpy(city, &buf[LOC_CITY], LEN_CITY); city[LEN_CITY] = 0;
186 strncpy(state, &buf[LOC_STATE], LEN_STATE); state[LEN_STATE] = 0;
187 strncpy(dphone, &buf[LOC_DPHONE], LEN_DPHONE); dphone[LEN_DPHONE] = 0;
188 strncpy(mphone, &buf[LOC_MPHONE], LEN_MPHONE); mphone[LEN_MPHONE] = 0;
189
190 strcpy(sname, name);
191 e.name = strtrim(sname);
192 p = index(name, ',');
093c49c9 193 if (p)
194 *p = 0;
e3c8ca24 195 e.last = strtrim(name);
093c49c9 196 if (p) {
e3c8ca24 197 p++;
198 while (isspace(*p))
199 p++;
200 e.first = p;
093c49c9 201 if (p = index(e.first, ' ')) {
202 *p = 0;
e3c8ca24 203 e.first = strtrim(e.first);
093c49c9 204 e.middle = strtrim(p + 1);
6d6c60e6 205 } else {
206 e.first = strtrim(e.first);
207 e.middle = "";
208 }
e3c8ca24 209 } else {
210 e.first = "";
211 e.middle = "";
212 }
039f9637 213 ends_jr = ends_iii = ends_iv = ends_sr = ends_ii = ends_v = 0;
093c49c9 214 LookForSt(e.last);
215 LookForO(e.last);
039f9637 216 LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv,
217 &ends_ii, &ends_v);
218 LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv,
219 &ends_ii, &ends_v);
093c49c9 220 FixCase(e.last);
221 FixCase(e.first);
222 FixCase(e.middle);
093c49c9 223
e3c8ca24 224 e.id = id;
093c49c9 225 e.id[LEN_ID] = 0;
226 e.eid = eid;
227 EncryptID(e.eid, e.id, e.first, e.last);
228
e3c8ca24 229 e.year = strtrim(year);
230 e.title = title;
231 if (e.year[0] == 'G') {
232 e.class = "G";
233 sprintf(title, "Grad Student");
234 } else {
093c49c9 235 e.class = classbuf;
e3c8ca24 236 sprintf(classbuf, "%d", nyear + 4 - atoi(e.year) + 1900);
237 sprintf(title, "Undergrad (class of %s)", classbuf);
093c49c9 238 }
e3c8ca24 239
240 e.course = strtrim(course);
241 e.address = strtrim(address);
242 e.dorm = strtrim(dorm_room);
243 e.city = strtrim(city);
244 e.state = strtrim(state);
245 e.dphone = strtrim(dphone);
246 e.mphone = strtrim(mphone);
093c49c9 247 return(&e);
248}
249
250
093c49c9 251process_entry(e)
252struct entry *e;
8638fcf9 253{
c48e3c93 254 int changed, nochange, encrypted;
5e2b5b5f 255 char buf[BUFSIZ], *from, *to;
8638fcf9 256 EXEC SQL BEGIN DECLARE SECTION;
ca64f2fb 257 char *first, *last, *middle, *eid, *title, *sid, *name, *rname, *rdept, *rtitle;
837b0ec6 258 char *rophone, *rhphone, *prog;
8638fcf9 259 char class[9], haddr[128], hphone[33], ophone[33], dept[33], raddr[128];
837b0ec6 260 char dfirst[17], dlast[17], dmiddle[17];
261 int id, status, who;
8638fcf9 262 EXEC SQL END DECLARE SECTION;
5e2b5b5f 263
837b0ec6 264 who = WHO;
265 prog = PROG;
5e2b5b5f 266 first = e->first;
9e4455c2 267 if (strlen(first) > 16)
268 first[16] = 0;
5e2b5b5f 269 last = e->last;
9e4455c2 270 if (strlen(last) > 16)
271 last[16] = 0;
ca64f2fb 272 middle = e->middle;
5e2b5b5f 273 eid = e->eid;
c48e3c93 274 sid = e->id;
5e2b5b5f 275 id = 0;
c48e3c93 276 encrypted = 0;
277
ca64f2fb 278 /* Get user info */
837b0ec6 279 EXEC SQL REPEATED SELECT users_id, first, last, middle, type, home_addr, home_phone, office_phone, status, department
280 INTO :id, :dfirst, :dlast, :dmiddle, :class, :haddr, :hphone, :ophone, :status, :dept
8638fcf9 281 FROM users
837b0ec6 282 WHERE clearid = :sid;
283 if (sqlfail()) {
284 if (sqlca.sqlcode == SQL_DUPLICATE) {
285 com_err(whoami, 0, "duplicate ID number %s on user %s %s", sid, first, last);
286 return;
e2048305 287 } else if (sqlca.sqlcode == SQL_DEADLOCK) {
288 com_err(whoami, MR_DEADLOCK, "looking up user %s", sid);
289 EXEC SQL ROLLBACK;
290 return process_entry(e);
837b0ec6 291 } else
292 sqlexit();
293 }
5e2b5b5f 294 if (id == 0) {
837b0ec6 295 EXEC SQL REPEATED SELECT users_id, first, last, middle, type, home_addr, home_phone, office_phone, status, department
296 INTO :id, :dfirst, :dlast, :dmiddle, :class, :haddr, :hphone, :ophone, :status, :dept
8638fcf9 297 FROM users
298 WHERE last = :last and first = :first and clearid = :eid;
e2048305 299 if (sqlfail()) {
300 if (sqlca.sqlcode == SQL_DEADLOCK) {
301 com_err(whoami, MR_DEADLOCK, "looking up user %s", sid);
302 EXEC SQL ROLLBACK;
303 return process_entry(e);
304 } else if (sqlca.sqlcode != SQL_DUPLICATE)
305 sqlexit();
306 }
c48e3c93 307 encrypted++;
308 if (id == 0) {
309 newuser(e);
310 return;
311 }
093c49c9 312 }
c48e3c93 313
ca64f2fb 314 /* See if class changed: if it's different, and the value in the database
315 * is not STAFF or SIPB, then update the database. Since they were on the
316 * students tape, make the account usable.
317 */
a262e022 318 if (strcmp(e->class, strtrim(class)) &&
319 strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
a97bc039 320 com_err(whoami, 0, "updating class for user %s %s from %s to %s",
321 first, last, class, e->class);
e3c8ca24 322 if (status == US_NOT_ALLOWED) status = US_NO_LOGIN_YET;
323 if (status == US_ENROLL_NOT_ALLOWED) status = US_ENROLLED;
5e2b5b5f 324 strcpy(class, e->class);
837b0ec6 325 EXEC SQL REPEATED UPDATE users
8638fcf9 326 SET type = :class, status = :status, modtime = 'now',
837b0ec6 327 modby = :who, modwith = :prog
8638fcf9 328 WHERE users_id = :id;
837b0ec6 329 if (sqlca.sqlcode != 0) {
330 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
331 exit(1);
332 }
093c49c9 333 }
c48e3c93 334
ca64f2fb 335 /* Update name if necessary */
336 if (strcmp(first, strtrim(dfirst)) ||
337 strcmp(last, strtrim(dlast)) ||
338 strcmp(middle, strtrim(dmiddle))) {
339 com_err(whoami, 0, "updating real name for %s %s", first, last);
340 EXEC SQL UPDATE users
341 SET first = :first, last = :last, middle = :middle,
342 modby = :who, modwith = :prog, modtime = 'now'
343 WHERE users_id = :id;
344 if (sqlca.sqlcode != 0) {
345 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
346 exit(1);
347 }
348 }
c48e3c93 349
ca64f2fb 350 /* Deal with updating the finger info if necessary */
a97bc039 351 changed = nochange = 0;
837b0ec6 352 if (encrypted) changed++;
e3c8ca24 353 strcpy(buf, e->address);
093c49c9 354 if (*e->dorm) {
355 strcat(buf, " ");
5e2b5b5f 356 strcat(buf, e->dorm);
093c49c9 357 }
358 if (*e->city) {
359 strcat(buf, " ");
5e2b5b5f 360 strcat(buf, e->city);
093c49c9 361 }
5e2b5b5f 362 FixCase(buf);
093c49c9 363 if (*e->state) {
364 strcat(buf, " ");
5e2b5b5f 365 strcat(buf, e->state);
093c49c9 366 }
5e2b5b5f 367 while (to = index(buf, ','))
368 *to = ';';
369 while (to = index(buf, ':'))
370 *to = ';';
a97bc039 371 if (newfinger) {
372 if (haddr[0] == ' ') {
373 strncpy(haddr, buf, 80);
374 haddr[80] = 0;
375 changed++;
376 } else if (strncmp(strtrim(haddr), buf, 80))
377 nochange++;
378 } else {
379 if (strncmp(strtrim(haddr), buf, 80))
380 changed++;
5e2b5b5f 381 strncpy(haddr, buf, 80);
a97bc039 382 haddr[80] = 0;
093c49c9 383 }
384 from = e->dphone;
385 to = buf;
386 while (*from) {
387 if (isdigit(*from))
388 *to++ = *from;
389 from++;
390 }
391 *to = 0;
a97bc039 392 if (newfinger) {
393 if (hphone[0] == ' ') {
394 strncpy(hphone, buf, 16);
395 hphone[16] = 0;
396 } else if (strncmp(strtrim(hphone), buf, 16))
397 nochange++;
398 } else {
399 if (strncmp(strtrim(hphone), buf, 16))
400 changed++;
5e2b5b5f 401 strncpy(hphone, buf, 16);
a97bc039 402 hphone[16] = 0;
093c49c9 403 }
404 from = e->mphone;
405 to = buf;
406 while (*from) {
407 if (isdigit(*from))
408 *to++ = *from;
409 from++;
410 }
411 *to = 0;
a97bc039 412 if (newfinger) {
413 if (ophone[0] == ' ') {
414 strncpy(ophone, buf, 12);
415 ophone[12] = 0;
416 } else if (strncmp(strtrim(ophone), buf, 12))
417 nochange++;
418 } else {
419 if (strncmp(strtrim(ophone), buf, 12))
420 changed++;
5e2b5b5f 421 strncpy(ophone, buf, 12);
a97bc039 422 ophone[12] = 0;
093c49c9 423 }
e3c8ca24 424 e->course = e->course;
a97bc039 425 if (newfinger) {
426 if (dept[0] == ' ') {
427 strncpy(dept, e->course, 12);
428 dept[12] = 0;
429 } else if (strncmp(strtrim(dept), e->course, 11))
430 nochange++;
431 } else {
432 if (strncmp(strtrim(dept), e->course, 11))
433 changed++;
5e2b5b5f 434 strncpy(dept, e->course, 12);
a97bc039 435 dept[12] = 0;
093c49c9 436 }
c48e3c93 437 sid = e->id;
438 name = e->name;
439 rdept = e->course;
440 rtitle = e->title;
441 rophone = e->mphone;
442 rhphone = e->dphone;
443 strcpy(raddr, e->address);
444 if (*e->dorm) {
445 strcat(raddr, " ");
446 strcat(raddr, e->dorm);
447 }
8638fcf9 448 strcat(raddr, "|");
c48e3c93 449 if (*e->city) {
c48e3c93 450 strcat(raddr, e->city);
8638fcf9 451 FixCase(raddr);
452 if (*e->state) {
453 strcat(raddr, " ");
454 if (isupper(e->state[0]) && isupper(e->state[1]) &&
455 isdigit(e->state[2]) && isdigit(e->state[3]) &&
456 isdigit(e->state[4]) && isdigit(e->state[5]) &&
457 isdigit(e->state[6])) {
458 sprintf(buf, "%c%c %s", e->state[0],e->state[1],
459 &(e->state[2]));
460 strcat(raddr, buf);
461 } else
462 strcat(raddr, e->state);
463 }
464 } else {
465 FixCase(raddr);
466 strcat(raddr, "MIT INTERDEPARTMENTAL MAIL");
c48e3c93 467 }
093c49c9 468 if (changed) {
5e2b5b5f 469 com_err(whoami, 0, "updating finger for %s %s", first, last);
8638fcf9 470 EXEC SQL REPEATED UPDATE users
471 SET home_addr = :haddr, home_phone = :hphone,
472 office_phone = :ophone, department = :dept,
837b0ec6 473 fmodtime = 'now', fmodby = :who, fmodwith = :prog,
8638fcf9 474 xname = :name, xdept = :rdept, xtitle = :rtitle,
475 xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
476 xmodtime = date('now'), clearid = :sid
477 WHERE users_id = :id;
837b0ec6 478 if (sqlca.sqlcode != 0) {
e2048305 479 if (sqlca.sqlcode == SQL_DEADLOCK) {
480 com_err(whoami, MR_DEADLOCK, "updating user %s", sid);
481 EXEC SQL ROLLBACK;
482 return process_entry(e);
483 } else {
484 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
485 exit(1);
486 }
837b0ec6 487 }
c48e3c93 488 } else {
8638fcf9 489 EXEC SQL REPEATED UPDATE users
490 SET xname = :name, xdept = :rdept, xtitle = :rtitle,
491 xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
492 xmodtime = date('now'), clearid = :sid
493 WHERE users_id = :id;
837b0ec6 494 if (sqlca.sqlcode != 0) {
e2048305 495 if (sqlca.sqlcode == SQL_DEADLOCK) {
496 com_err(whoami, MR_DEADLOCK, "updating user %s", sid);
497 EXEC SQL ROLLBACK;
498 return process_entry(e);
499 } else {
500 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
501 exit(1);
502 }
837b0ec6 503 }
e3c8ca24 504 }
8638fcf9 505}
093c49c9 506
5e2b5b5f 507
508newuser(e)
093c49c9 509struct entry *e;
8638fcf9 510{
5e2b5b5f 511 char buf[512], *from, *to;
8638fcf9 512 EXEC SQL BEGIN DECLARE SECTION;
513 int id, uid, who;
514 char *last, *first, *class, *middle, login[9], *sid, fullname[65], *prog;
515 char haddr[81], hphone[17], ophone[13], dept[24], *title, raddr[81], *name;
516 EXEC SQL END DECLARE SECTION;
517
518 who = WHO;
519 prog = PROG;
e3c8ca24 520 strcpy(buf, e->address);
5e2b5b5f 521 if (*e->dorm) {
522 strcat(buf, " ");
e3c8ca24 523 strcat(buf, e->dorm);
5e2b5b5f 524 }
525 if (*e->city) {
526 strcat(buf, " ");
e3c8ca24 527 strcat(buf, e->city);
5e2b5b5f 528 }
529 if (*e->state) {
530 strcat(buf, " ");
e3c8ca24 531 strcat(buf, e->state);
5e2b5b5f 532 }
533 strncpy(haddr, buf, 80);
534 from = e->dphone;
535 to = buf;
536 while (*from) {
537 if (isdigit(*from))
538 *to++ = *from;
539 from++;
540 }
541 *to = 0;
542 strncpy(hphone, buf, 16);
543 from = e->mphone;
544 to = buf;
545 while (*from) {
546 if (isdigit(*from))
547 *to++ = *from;
548 from++;
549 }
550 *to = 0;
551 strncpy(ophone, buf, 12);
5e2b5b5f 552 strncpy(dept, e->course, 12);
5e2b5b5f 553
837b0ec6 554 id = set_next_users_id(0);
555 uid = set_next_uid(1);
5e2b5b5f 556 sprintf(login, "#%d", uid);
557 last = e->last;
558 first = e->first;
559 middle = e->middle;
c48e3c93 560 sid = e->id;
5e2b5b5f 561 class = e->class;
c48e3c93 562 title = e->title;
5e2b5b5f 563 if (*middle)
564 sprintf(fullname, "%s %s %s", first, middle, last);
565 else
566 sprintf(fullname, "%s %s", first, last);
8638fcf9 567 name = e->name;
568 strcpy(raddr, e->address);
569 if (*e->dorm) {
570 strcat(raddr, " ");
571 strcat(raddr, e->dorm);
572 }
573 strcat(raddr, "|");
574 if (*e->city) {
575 strcat(raddr, e->city);
576 FixCase(raddr);
577 if (*e->state) {
578 strcat(raddr, " ");
579 if (isupper(e->state[0]) && isupper(e->state[1]) &&
580 isdigit(e->state[2]) && isdigit(e->state[3]) &&
581 isdigit(e->state[4]) && isdigit(e->state[5]) &&
582 isdigit(e->state[6])) {
583 sprintf(buf, "%c%c %s", e->state[0],e->state[1],
584 &(e->state[2]));
585 strcat(raddr, buf);
586 } else
587 strcat(raddr, e->state);
588 }
589 } else {
590 FixCase(raddr);
591 strcat(raddr, "MIT INTERDEPARTMENTAL MAIL");
592 }
837b0ec6 593 EXEC SQL REPEATED INSERT INTO users
8638fcf9 594 (login, users_id, uid, shell, last, first, middle, status,
595 clearid, type, modtime, modby, modwith, fullname, home_addr,
596 home_phone, office_phone, department, fmodtime, fmodby, fmodwith,
597 potype, xname, xdept, xtitle, xaddress, xphone1, xphone2, xmodtime)
598 VALUES (:login, :id, :uid, '/bin/csh', :last, :first, :middle, 0,
599 :sid, :class, 'now', :who, :prog, :fullname, :haddr, :hphone,
600 :ophone, :dept, 'now', :who, :prog, 'NONE', :name, :dept,
601 :title, :raddr, :hphone, :ophone, date('now'));
837b0ec6 602 if (sqlca.sqlcode != 0) {
e2048305 603 if (sqlca.sqlcode == SQL_DEADLOCK) {
604 com_err(whoami, MR_DEADLOCK, "adding user %s", sid);
605 EXEC SQL ROLLBACK;
606 return newuser(e);
607 } else {
608 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
609 exit(1);
610 }
837b0ec6 611 } else
612 com_err(whoami, 0, "adding user %s %s", e->first, e->last);
8638fcf9 613}
5e2b5b5f 614
615
837b0ec6 616
617set_next_users_id(limit)
27736587 618 int limit;
8638fcf9 619{
620 EXEC SQL BEGIN DECLARE SECTION;
837b0ec6 621 int rowcount, flag, value, retval;
8638fcf9 622 EXEC SQL END DECLARE SECTION;
5e2b5b5f 623
837b0ec6 624 EXEC SQL REPEATED SELECT value INTO :value FROM numvalues
625 WHERE name = 'users_id';
626 if (sqlfail()) sqlexit();
8638fcf9 627 if (sqlca.sqlerrd[2] != 1) {
628 EXEC SQL ROLLBACK;
629 com_err(whoami, MR_INTERNAL, "values table inconsistancy");
630 exit(1);
093c49c9 631 }
5e2b5b5f 632
8638fcf9 633 flag = 0;
837b0ec6 634 EXEC SQL REPEATED SELECT users_id INTO :flag FROM users
635 WHERE users_id = :value;
636 if (sqlfail()) sqlexit();
8638fcf9 637 if (sqlca.sqlerrd[2] == 0)
638 flag = 0;
639 while (flag) {
5e2b5b5f 640 value++;
27736587 641 if (limit && value > MAX_ID_VALUE)
5e2b5b5f 642 value = MIN_ID_VALUE;
8638fcf9 643 flag = 0;
837b0ec6 644 EXEC SQL REPEATED SELECT users_id INTO :flag FROM users
645 WHERE users_id = :value;
646 if (sqlfail()) sqlexit();
8638fcf9 647 if (sqlca.sqlerrd[2] == 0)
648 flag = 0;
5e2b5b5f 649 }
650
837b0ec6 651 retval = value++;
8638fcf9 652 if (limit && value > MAX_ID_VALUE)
653 value = MIN_ID_VALUE;
837b0ec6 654 EXEC SQL REPEATED UPDATE numvalues SET value = :value
655 WHERE name = 'users_id';
656 if (sqlca.sqlcode != 0) {
657 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
658 exit(1);
659 }
660 return(retval);
661}
662
663set_next_uid(limit)
664 int limit;
665{
666 EXEC SQL BEGIN DECLARE SECTION;
667 int rowcount, flag, value, retval;
668 EXEC SQL END DECLARE SECTION;
669
670 EXEC SQL REPEATED SELECT value INTO :value FROM numvalues
671 WHERE name = 'uid';
672 if (sqlfail()) sqlexit();
673 if (sqlca.sqlerrd[2] != 1) {
674 EXEC SQL ROLLBACK;
675 com_err(whoami, MR_INTERNAL, "values table inconsistancy");
676 exit(1);
677 }
678
679 flag = 0;
680 EXEC SQL REPEATED SELECT uid INTO :flag FROM users WHERE uid = :value;
681 if (sqlfail()) sqlexit();
682 if (sqlca.sqlerrd[2] == 0)
683 flag = 0;
684 while (flag) {
685 value++;
686 if (limit && value > MAX_ID_VALUE)
687 value = MIN_ID_VALUE;
688 flag = 0;
689 EXEC SQL REPEATED SELECT uid INTO :flag FROM users WHERE uid = :value;
690 if (sqlfail()) sqlexit();
691 if (sqlca.sqlerrd[2] == 0)
692 flag = 0;
693 }
694
695 retval = value++;
696 if (limit && value > MAX_ID_VALUE)
697 value = MIN_ID_VALUE;
698 EXEC SQL REPEATED UPDATE numvalues SET value = :value WHERE name = 'uid';
699 if (sqlca.sqlcode != 0) {
700 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
701 exit(1);
702 }
703 return(retval);
704}
705
706
707sqlexit()
708{
e2048305 709 if (sqlca.sqlcode == SQL_DEADLOCK)
710 com_err(whoami, MR_DEADLOCK, "unrecoverable ingres error %d",
711 sqlca.sqlcode);
712 else
713 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
837b0ec6 714 EXEC SQL ROLLBACK WORK;
715 exit(1);
8638fcf9 716}
This page took 0.388084 seconds and 5 git commands to generate.