]> andersk Git - moira.git/blame - regtape/students.dc
update name if necessary
[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;
ca64f2fb 250 char *first, *last, *middle, *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;
ca64f2fb 265 middle = e->middle;
5e2b5b5f 266 eid = e->eid;
c48e3c93 267 sid = e->id;
5e2b5b5f 268 id = 0;
c48e3c93 269 encrypted = 0;
270
ca64f2fb 271 /* Get user info */
837b0ec6 272 EXEC SQL REPEATED SELECT users_id, first, last, middle, type, home_addr, home_phone, office_phone, status, department
273 INTO :id, :dfirst, :dlast, :dmiddle, :class, :haddr, :hphone, :ophone, :status, :dept
8638fcf9 274 FROM users
837b0ec6 275 WHERE clearid = :sid;
276 if (sqlfail()) {
277 if (sqlca.sqlcode == SQL_DUPLICATE) {
278 com_err(whoami, 0, "duplicate ID number %s on user %s %s", sid, first, last);
279 return;
280 } else
281 sqlexit();
282 }
5e2b5b5f 283 if (id == 0) {
837b0ec6 284 EXEC SQL REPEATED SELECT users_id, first, last, middle, type, home_addr, home_phone, office_phone, status, department
285 INTO :id, :dfirst, :dlast, :dmiddle, :class, :haddr, :hphone, :ophone, :status, :dept
8638fcf9 286 FROM users
287 WHERE last = :last and first = :first and clearid = :eid;
837b0ec6 288 if (sqlfail() && sqlca.sqlcode != SQL_DUPLICATE) sqlexit();
c48e3c93 289 encrypted++;
290 if (id == 0) {
291 newuser(e);
292 return;
293 }
093c49c9 294 }
c48e3c93 295
ca64f2fb 296 /* See if class changed: if it's different, and the value in the database
297 * is not STAFF or SIPB, then update the database. Since they were on the
298 * students tape, make the account usable.
299 */
a262e022 300 if (strcmp(e->class, strtrim(class)) &&
301 strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
a97bc039 302 com_err(whoami, 0, "updating class for user %s %s from %s to %s",
303 first, last, class, e->class);
e3c8ca24 304 if (status == US_NOT_ALLOWED) status = US_NO_LOGIN_YET;
305 if (status == US_ENROLL_NOT_ALLOWED) status = US_ENROLLED;
5e2b5b5f 306 strcpy(class, e->class);
837b0ec6 307 EXEC SQL REPEATED UPDATE users
8638fcf9 308 SET type = :class, status = :status, modtime = 'now',
837b0ec6 309 modby = :who, modwith = :prog
8638fcf9 310 WHERE users_id = :id;
837b0ec6 311 if (sqlca.sqlcode != 0) {
312 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
313 exit(1);
314 }
093c49c9 315 }
c48e3c93 316
ca64f2fb 317 /* Update name if necessary */
318 if (strcmp(first, strtrim(dfirst)) ||
319 strcmp(last, strtrim(dlast)) ||
320 strcmp(middle, strtrim(dmiddle))) {
321 com_err(whoami, 0, "updating real name for %s %s", first, last);
322 EXEC SQL UPDATE users
323 SET first = :first, last = :last, middle = :middle,
324 modby = :who, modwith = :prog, modtime = 'now'
325 WHERE users_id = :id;
326 if (sqlca.sqlcode != 0) {
327 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
328 exit(1);
329 }
330 }
c48e3c93 331
ca64f2fb 332 /* Deal with updating the finger info if necessary */
a97bc039 333 changed = nochange = 0;
837b0ec6 334 if (encrypted) changed++;
e3c8ca24 335 strcpy(buf, e->address);
093c49c9 336 if (*e->dorm) {
337 strcat(buf, " ");
5e2b5b5f 338 strcat(buf, e->dorm);
093c49c9 339 }
340 if (*e->city) {
341 strcat(buf, " ");
5e2b5b5f 342 strcat(buf, e->city);
093c49c9 343 }
5e2b5b5f 344 FixCase(buf);
093c49c9 345 if (*e->state) {
346 strcat(buf, " ");
5e2b5b5f 347 strcat(buf, e->state);
093c49c9 348 }
5e2b5b5f 349 while (to = index(buf, ','))
350 *to = ';';
351 while (to = index(buf, ':'))
352 *to = ';';
a97bc039 353 if (newfinger) {
354 if (haddr[0] == ' ') {
355 strncpy(haddr, buf, 80);
356 haddr[80] = 0;
357 changed++;
358 } else if (strncmp(strtrim(haddr), buf, 80))
359 nochange++;
360 } else {
361 if (strncmp(strtrim(haddr), buf, 80))
362 changed++;
5e2b5b5f 363 strncpy(haddr, buf, 80);
a97bc039 364 haddr[80] = 0;
093c49c9 365 }
366 from = e->dphone;
367 to = buf;
368 while (*from) {
369 if (isdigit(*from))
370 *to++ = *from;
371 from++;
372 }
373 *to = 0;
a97bc039 374 if (newfinger) {
375 if (hphone[0] == ' ') {
376 strncpy(hphone, buf, 16);
377 hphone[16] = 0;
378 } else if (strncmp(strtrim(hphone), buf, 16))
379 nochange++;
380 } else {
381 if (strncmp(strtrim(hphone), buf, 16))
382 changed++;
5e2b5b5f 383 strncpy(hphone, buf, 16);
a97bc039 384 hphone[16] = 0;
093c49c9 385 }
386 from = e->mphone;
387 to = buf;
388 while (*from) {
389 if (isdigit(*from))
390 *to++ = *from;
391 from++;
392 }
393 *to = 0;
a97bc039 394 if (newfinger) {
395 if (ophone[0] == ' ') {
396 strncpy(ophone, buf, 12);
397 ophone[12] = 0;
398 } else if (strncmp(strtrim(ophone), buf, 12))
399 nochange++;
400 } else {
401 if (strncmp(strtrim(ophone), buf, 12))
402 changed++;
5e2b5b5f 403 strncpy(ophone, buf, 12);
a97bc039 404 ophone[12] = 0;
093c49c9 405 }
e3c8ca24 406 e->course = e->course;
a97bc039 407 if (newfinger) {
408 if (dept[0] == ' ') {
409 strncpy(dept, e->course, 12);
410 dept[12] = 0;
411 } else if (strncmp(strtrim(dept), e->course, 11))
412 nochange++;
413 } else {
414 if (strncmp(strtrim(dept), e->course, 11))
415 changed++;
5e2b5b5f 416 strncpy(dept, e->course, 12);
a97bc039 417 dept[12] = 0;
093c49c9 418 }
c48e3c93 419 sid = e->id;
420 name = e->name;
421 rdept = e->course;
422 rtitle = e->title;
423 rophone = e->mphone;
424 rhphone = e->dphone;
425 strcpy(raddr, e->address);
426 if (*e->dorm) {
427 strcat(raddr, " ");
428 strcat(raddr, e->dorm);
429 }
8638fcf9 430 strcat(raddr, "|");
c48e3c93 431 if (*e->city) {
c48e3c93 432 strcat(raddr, e->city);
8638fcf9 433 FixCase(raddr);
434 if (*e->state) {
435 strcat(raddr, " ");
436 if (isupper(e->state[0]) && isupper(e->state[1]) &&
437 isdigit(e->state[2]) && isdigit(e->state[3]) &&
438 isdigit(e->state[4]) && isdigit(e->state[5]) &&
439 isdigit(e->state[6])) {
440 sprintf(buf, "%c%c %s", e->state[0],e->state[1],
441 &(e->state[2]));
442 strcat(raddr, buf);
443 } else
444 strcat(raddr, e->state);
445 }
446 } else {
447 FixCase(raddr);
448 strcat(raddr, "MIT INTERDEPARTMENTAL MAIL");
c48e3c93 449 }
093c49c9 450 if (changed) {
5e2b5b5f 451 com_err(whoami, 0, "updating finger for %s %s", first, last);
8638fcf9 452 EXEC SQL REPEATED UPDATE users
453 SET home_addr = :haddr, home_phone = :hphone,
454 office_phone = :ophone, department = :dept,
837b0ec6 455 fmodtime = 'now', fmodby = :who, fmodwith = :prog,
8638fcf9 456 xname = :name, xdept = :rdept, xtitle = :rtitle,
457 xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
458 xmodtime = date('now'), clearid = :sid
459 WHERE users_id = :id;
837b0ec6 460 if (sqlca.sqlcode != 0) {
461 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
462 exit(1);
463 }
c48e3c93 464 } else {
8638fcf9 465 EXEC SQL REPEATED UPDATE users
466 SET xname = :name, xdept = :rdept, xtitle = :rtitle,
467 xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
468 xmodtime = date('now'), clearid = :sid
469 WHERE users_id = :id;
837b0ec6 470 if (sqlca.sqlcode != 0) {
471 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
472 exit(1);
473 }
e3c8ca24 474 }
8638fcf9 475}
093c49c9 476
5e2b5b5f 477
478newuser(e)
093c49c9 479struct entry *e;
8638fcf9 480{
5e2b5b5f 481 char buf[512], *from, *to;
8638fcf9 482 EXEC SQL BEGIN DECLARE SECTION;
483 int id, uid, who;
484 char *last, *first, *class, *middle, login[9], *sid, fullname[65], *prog;
485 char haddr[81], hphone[17], ophone[13], dept[24], *title, raddr[81], *name;
486 EXEC SQL END DECLARE SECTION;
487
488 who = WHO;
489 prog = PROG;
e3c8ca24 490 strcpy(buf, e->address);
5e2b5b5f 491 if (*e->dorm) {
492 strcat(buf, " ");
e3c8ca24 493 strcat(buf, e->dorm);
5e2b5b5f 494 }
495 if (*e->city) {
496 strcat(buf, " ");
e3c8ca24 497 strcat(buf, e->city);
5e2b5b5f 498 }
499 if (*e->state) {
500 strcat(buf, " ");
e3c8ca24 501 strcat(buf, e->state);
5e2b5b5f 502 }
503 strncpy(haddr, buf, 80);
504 from = e->dphone;
505 to = buf;
506 while (*from) {
507 if (isdigit(*from))
508 *to++ = *from;
509 from++;
510 }
511 *to = 0;
512 strncpy(hphone, buf, 16);
513 from = e->mphone;
514 to = buf;
515 while (*from) {
516 if (isdigit(*from))
517 *to++ = *from;
518 from++;
519 }
520 *to = 0;
521 strncpy(ophone, buf, 12);
5e2b5b5f 522 strncpy(dept, e->course, 12);
5e2b5b5f 523
837b0ec6 524 id = set_next_users_id(0);
525 uid = set_next_uid(1);
5e2b5b5f 526 sprintf(login, "#%d", uid);
527 last = e->last;
528 first = e->first;
529 middle = e->middle;
c48e3c93 530 sid = e->id;
5e2b5b5f 531 class = e->class;
c48e3c93 532 title = e->title;
5e2b5b5f 533 if (*middle)
534 sprintf(fullname, "%s %s %s", first, middle, last);
535 else
536 sprintf(fullname, "%s %s", first, last);
8638fcf9 537 name = e->name;
538 strcpy(raddr, e->address);
539 if (*e->dorm) {
540 strcat(raddr, " ");
541 strcat(raddr, e->dorm);
542 }
543 strcat(raddr, "|");
544 if (*e->city) {
545 strcat(raddr, e->city);
546 FixCase(raddr);
547 if (*e->state) {
548 strcat(raddr, " ");
549 if (isupper(e->state[0]) && isupper(e->state[1]) &&
550 isdigit(e->state[2]) && isdigit(e->state[3]) &&
551 isdigit(e->state[4]) && isdigit(e->state[5]) &&
552 isdigit(e->state[6])) {
553 sprintf(buf, "%c%c %s", e->state[0],e->state[1],
554 &(e->state[2]));
555 strcat(raddr, buf);
556 } else
557 strcat(raddr, e->state);
558 }
559 } else {
560 FixCase(raddr);
561 strcat(raddr, "MIT INTERDEPARTMENTAL MAIL");
562 }
837b0ec6 563 EXEC SQL REPEATED INSERT INTO users
8638fcf9 564 (login, users_id, uid, shell, last, first, middle, status,
565 clearid, type, modtime, modby, modwith, fullname, home_addr,
566 home_phone, office_phone, department, fmodtime, fmodby, fmodwith,
567 potype, xname, xdept, xtitle, xaddress, xphone1, xphone2, xmodtime)
568 VALUES (:login, :id, :uid, '/bin/csh', :last, :first, :middle, 0,
569 :sid, :class, 'now', :who, :prog, :fullname, :haddr, :hphone,
570 :ophone, :dept, 'now', :who, :prog, 'NONE', :name, :dept,
571 :title, :raddr, :hphone, :ophone, date('now'));
837b0ec6 572 if (sqlca.sqlcode != 0) {
573 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
574 exit(1);
575 } else
576 com_err(whoami, 0, "adding user %s %s", e->first, e->last);
8638fcf9 577}
5e2b5b5f 578
579
837b0ec6 580
581set_next_users_id(limit)
27736587 582 int limit;
8638fcf9 583{
584 EXEC SQL BEGIN DECLARE SECTION;
837b0ec6 585 int rowcount, flag, value, retval;
8638fcf9 586 EXEC SQL END DECLARE SECTION;
5e2b5b5f 587
837b0ec6 588 EXEC SQL REPEATED SELECT value INTO :value FROM numvalues
589 WHERE name = 'users_id';
590 if (sqlfail()) sqlexit();
8638fcf9 591 if (sqlca.sqlerrd[2] != 1) {
592 EXEC SQL ROLLBACK;
593 com_err(whoami, MR_INTERNAL, "values table inconsistancy");
594 exit(1);
093c49c9 595 }
5e2b5b5f 596
8638fcf9 597 flag = 0;
837b0ec6 598 EXEC SQL REPEATED SELECT users_id INTO :flag FROM users
599 WHERE users_id = :value;
600 if (sqlfail()) sqlexit();
8638fcf9 601 if (sqlca.sqlerrd[2] == 0)
602 flag = 0;
603 while (flag) {
5e2b5b5f 604 value++;
27736587 605 if (limit && value > MAX_ID_VALUE)
5e2b5b5f 606 value = MIN_ID_VALUE;
8638fcf9 607 flag = 0;
837b0ec6 608 EXEC SQL REPEATED SELECT users_id INTO :flag FROM users
609 WHERE users_id = :value;
610 if (sqlfail()) sqlexit();
8638fcf9 611 if (sqlca.sqlerrd[2] == 0)
612 flag = 0;
5e2b5b5f 613 }
614
837b0ec6 615 retval = value++;
8638fcf9 616 if (limit && value > MAX_ID_VALUE)
617 value = MIN_ID_VALUE;
837b0ec6 618 EXEC SQL REPEATED UPDATE numvalues SET value = :value
619 WHERE name = 'users_id';
620 if (sqlca.sqlcode != 0) {
621 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
622 exit(1);
623 }
624 return(retval);
625}
626
627set_next_uid(limit)
628 int limit;
629{
630 EXEC SQL BEGIN DECLARE SECTION;
631 int rowcount, flag, value, retval;
632 EXEC SQL END DECLARE SECTION;
633
634 EXEC SQL REPEATED SELECT value INTO :value FROM numvalues
635 WHERE name = 'uid';
636 if (sqlfail()) sqlexit();
637 if (sqlca.sqlerrd[2] != 1) {
638 EXEC SQL ROLLBACK;
639 com_err(whoami, MR_INTERNAL, "values table inconsistancy");
640 exit(1);
641 }
642
643 flag = 0;
644 EXEC SQL REPEATED SELECT uid INTO :flag FROM users WHERE uid = :value;
645 if (sqlfail()) sqlexit();
646 if (sqlca.sqlerrd[2] == 0)
647 flag = 0;
648 while (flag) {
649 value++;
650 if (limit && value > MAX_ID_VALUE)
651 value = MIN_ID_VALUE;
652 flag = 0;
653 EXEC SQL REPEATED SELECT uid INTO :flag FROM users WHERE uid = :value;
654 if (sqlfail()) sqlexit();
655 if (sqlca.sqlerrd[2] == 0)
656 flag = 0;
657 }
658
659 retval = value++;
660 if (limit && value > MAX_ID_VALUE)
661 value = MIN_ID_VALUE;
662 EXEC SQL REPEATED UPDATE numvalues SET value = :value WHERE name = 'uid';
663 if (sqlca.sqlcode != 0) {
664 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
665 exit(1);
666 }
667 return(retval);
668}
669
670
671sqlexit()
672{
673 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
674 EXEC SQL ROLLBACK WORK;
675 exit(1);
8638fcf9 676}
This page took 0.19616 seconds and 5 git commands to generate.