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