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