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