]> andersk Git - moira.git/blob - regtape/employee.pc
fix bug in department size change
[moira.git] / regtape / employee.pc
1 /* $Id$
2  *
3  * Load data into Moira from Personnel Office data file
4  *
5  * Copyright (C) 1990-1998 by the Massachusetts Institute of Technology
6  * For copying and distribution information, please see the file
7  * <mit-copyright.h>.
8  */
9
10 #include <mit-copyright.h>
11 #include <moira.h>
12 #include <moira_site.h>
13 #include <moira_schema.h>
14
15 #include <ctype.h>
16 #include <stdio.h>
17 #include <string.h>
18
19 EXEC SQL INCLUDE sqlca;
20 extern void sqlglm(char *, unsigned int *, unsigned int *);
21
22 RCSID("$Header$");
23
24 #define WHO 11859               /* root */
25 #define PROG "emp-tape"
26
27 #define MAX_ID_VALUE    31999
28 #define MIN_ID_VALUE    101
29
30 /* File format is:
31
32 0-8     id number
33 9-38    name
34 39-62   office address
35 63-74   phone1
36 75-86   phone2
37 87-106  dept
38 107-156 title
39 157-186 username
40 187-241 host
41
42 */
43
44 #define LOC_ID 0
45 #define LOC_NAME 9
46 #define LOC_OFFICE 39
47 #define LOC_PHONE 63
48 #define LOC_PHONE2 75
49 #define LOC_DEPT 87
50 #define LOC_TITLE 137
51 #define LOC_USERNAME 187
52 #define LOC_HOST 217
53
54 #define LEN_ID 9
55 #define LEN_NAME 30
56 #define LEN_OFFICE 24
57 #define LEN_PHONE 12
58 #define LEN_PHONE2 12
59 #define LEN_DEPT 50
60 #define LEN_TITLE 50
61 #define LEN_USERNAME 30
62 #define LEN_HOST 55
63
64
65 struct entry {
66   char *name;
67   char *last;
68   char *first;
69   char *middle;
70   char *title;
71   char *class;
72   char *id;
73   char *dept;
74   char *address;
75   char *phone;
76   char *phone2;
77   int highid;
78 };
79
80 struct entry *get_next_entry(FILE *in);
81 void process_entry(struct entry *e);
82 void newuser(struct entry *e);
83 int set_next_users_id(int limit);
84 int set_next_uid(int high);
85 void sqlexit(void);
86 void dbmserr(char *where, int what);
87
88 char *whoami;
89 int newfinger = 0, debug = 0, highid = 0;
90
91 #define sqlfail() (sqlca.sqlcode && sqlca.sqlcode != 1403)
92 #define SQL_DUPLICATE -2112
93
94
95 int main(int argc, char **argv)
96 {
97   FILE *in;
98   struct entry *e;
99   int i, wait = 0;
100   char buf[80], *file = NULL;
101   EXEC SQL BEGIN DECLARE SECTION;
102   char *db = "moira";
103   EXEC SQL END DECLARE SECTION;
104
105   whoami = strrchr(argv[0], '/');
106   if (whoami)
107     whoami++;
108   else
109     whoami = argv[0];
110
111   setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
112   setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
113
114   for (i = 1; i < argc; i++)
115     {
116       if (!strcmp(argv[i], "-w"))
117         wait++;
118       else if (!strcmp(argv[i], "-n"))
119         newfinger++;
120       else if (!strcmp(argv[i], "-d"))
121         debug++;
122       else if (!strcmp(argv[i], "-h"))
123         highid++;
124       else if (file)
125         fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
126       else
127         file = argv[i];
128     }
129
130   in = fopen(file, "r");
131   if (!in)
132     {
133       fprintf(stderr, "Unable to open %s for input\n", file);
134       exit(1);
135     }
136
137   initialize_sms_error_table();
138
139   EXEC SQL CONNECT :db IDENTIFIED BY :db;
140   if (sqlca.sqlcode)
141     {
142       dbmserr("opening database", sqlca.sqlcode);
143       exit(1);
144     }
145
146   while ((e = get_next_entry(in)))
147     {
148       process_entry(e);
149       EXEC SQL COMMIT WORK;
150       if (sqlca.sqlcode)
151         {
152           dbmserr("committing work", sqlca.sqlcode);
153           exit(1);
154         }
155       if (wait)
156         {
157           printf("Next");
158           fflush(stdout);
159           fgets(buf, sizeof(buf), stdin);
160         }
161     }
162
163   exit(0);
164 }
165
166 struct entry *get_next_entry(FILE *in)
167 {
168   static struct entry e;
169   static char buf[BUFSIZ];
170   static char name[LEN_NAME + 1], sname[LEN_NAME + 1], id[LEN_ID + 1];
171   static char office[LEN_OFFICE + 1], phone[LEN_PHONE + 1];
172   static char phone2[LEN_PHONE2 + 1], dept[LEN_DEPT + 1], title[LEN_TITLE + 1];
173   static char username[LEN_USERNAME + 1], host[LEN_HOST + 1];
174   int ends_sr, ends_jr, ends_iii, ends_iv, ends_ii, ends_v;
175   char *p, *q;
176
177   if (!fgets(buf, sizeof(buf), in))
178     return NULL;
179
180   strncpy(id, &buf[LOC_ID], LEN_ID);
181   id[LEN_ID] = '\0';
182   strncpy(name, &buf[LOC_NAME], LEN_NAME);
183   name[LEN_NAME] = '\0';
184   strncpy(office, &buf[LOC_OFFICE], LEN_OFFICE);
185   office[LEN_OFFICE] = '\0';
186   strncpy(phone, &buf[LOC_PHONE], LEN_PHONE);
187   phone[LEN_PHONE] = '\0';
188   strncpy(phone2, &buf[LOC_PHONE2], LEN_PHONE2);
189   phone2[LEN_PHONE2] = '\0';
190   strncpy(dept, &buf[LOC_DEPT], LEN_DEPT);
191   dept[LEN_DEPT] = '\0';
192   strncpy(title, &buf[LOC_TITLE], LEN_TITLE);
193   title[LEN_TITLE] = '\0';
194   strncpy(username, &buf[LOC_USERNAME], LEN_USERNAME);
195   username[LEN_USERNAME] = '\0';
196   strncpy(host, &buf[LOC_HOST], LEN_HOST);
197   host[LEN_HOST] = '\0';
198
199   strcpy(sname, name);
200   e.name = strtrim(sname);
201   p = strchr(name, ',');
202   if (p)
203     *p = '\0';
204   e.last = strtrim(name);
205   if (p)
206     {
207       p++;
208       while (isspace(*p))
209         p++;
210       e.first = p;
211       if ((p = strchr(e.first, ' ')))
212         {
213           *p = '\0';
214           e.first = strtrim(e.first);
215           e.middle = strtrim(p + 1);
216         }
217       else
218         {
219           e.first = strtrim(e.first);
220           e.middle = "";
221         }
222     }
223   else
224     {
225       e.first = "";
226       e.middle = "";
227     }
228   ends_sr = ends_jr = ends_iii = ends_iv = ends_ii = ends_v = 0;
229   LookForSt(e.last);
230   LookForO(e.last);
231   LookForJrAndIII(e.last, &ends_jr, &ends_sr, &ends_ii, &ends_iii,
232                   &ends_iv, &ends_v);
233   LookForJrAndIII(e.first, &ends_jr, &ends_sr, &ends_ii, &ends_iii,
234                   &ends_iv, &ends_v);
235   FixCase(e.last);
236   FixCase(e.first);
237   FixCase(e.middle);
238
239   e.id = id;
240
241   /* The following is really gross, but it happens to successfully convert
242    * new-style Warehouse office descriptions into (more-readable) old-style
243    * Personnel Office office descriptions.
244    */
245   e.address = p = strtrim(office);
246   while (*p && !isspace(*p))
247     p++;
248   q = p;
249   while (isspace(*q))
250     q++;
251   if (*q && q < e.address + LEN_OFFICE / 2)
252     {
253       *p++ = '-';
254       while (*q && q < e.address + LEN_OFFICE / 2)
255         {
256           if (*q != ' ' && *q != '-')
257             *p++ = *q;
258           if (q > p)
259             *q = ' ';
260           q++;
261         }
262       memset(p, ' ', q - p);
263     }
264
265   p = e.address + LEN_OFFICE / 2;
266   while (*p && !isspace(*p))
267     p++;
268   q = p;
269   while (isspace(*q))
270     q++;
271   if (*q)
272     {
273       *p++ = '-';
274       while (*q)
275         {
276           if (*q != ' ' && *q != '-')
277             *p++ = *q;
278           if (q > p)
279             *q = ' ';
280           q++;
281         }
282       memset(p, ' ', q - p);
283     }
284   strtrim(e.address);
285
286   e.phone = strtrim(phone);
287   e.phone2 = strtrim(phone2);
288   e.dept = strtrim(dept);
289   e.title = strtrim(title);
290
291   e.class = "MITS";
292   e.highid = highid;
293   if (strstr(e.title, "PROF") || strstr(e.title, "LECTURE"))
294     e.class = "FACULTY";
295   if (!strcmp(e.dept, "LINCOLN LAB"))
296     {
297       e.class = "LINCOLN";
298       e.highid = 1;
299     }
300
301   return &e;
302 }
303
304 void process_entry(struct entry *e)
305 {
306   int changed, nochange;
307   char buf[MAX_FIELD_WIDTH], *from, *to;
308   EXEC SQL BEGIN DECLARE SECTION;
309   char *first, *last, *middle, *sid, *name, *rdept;
310   char *rtitle, *raddr, *rhphone, *rophone, *prog;
311   char class[USERS_TYPE_SIZE], oaddr[USERS_OFFICE_ADDR_SIZE];
312   char ophone[USERS_OFFICE_PHONE_SIZE], dept[USERS_DEPARTMENT_SIZE];
313   char dfirst[USERS_FIRST_SIZE], dlast[USERS_LAST_SIZE];
314   char dmiddle[USERS_MIDDLE_SIZE];
315   int id, status, who;
316   EXEC SQL END DECLARE SECTION;
317
318   who = WHO;
319   prog = PROG;
320   first = e->first;
321   if (strlen(first) > USERS_FIRST_SIZE - 1)
322     first[USERS_FIRST_SIZE - 1] = '\0';
323   last = e->last;
324   if (strlen(last) > USERS_LAST_SIZE - 1)
325     last[USERS_LAST_SIZE - 1] = '\0';
326   middle = e->middle;
327   if (strlen(middle) > USERS_MIDDLE_SIZE - 1)
328     middle[USERS_MIDDLE_SIZE - 1] = '\0';
329   sid = e->id;
330   id = 0;
331
332   /* Get user info */
333   EXEC SQL SELECT users_id, first, last, middle, type, office_addr,
334     office_phone, department, status
335     INTO :id, :dfirst, :dlast, :dmiddle, :class, :oaddr,
336     :ophone, :dept, :status
337     FROM users
338     WHERE clearid = :sid;
339   if (sqlfail())
340     {
341       if (sqlca.sqlcode == SQL_DUPLICATE)
342         {
343           com_err(whoami, 0, "duplicate ID number %s on user %s %s",
344                   sid, first, last);
345           return;
346         }
347       else
348         sqlexit();
349     }
350   if (id == 0)
351     {
352       newuser(e);
353       return;
354     }
355
356   /* Update class/state if necessary.  (Exclude several spacial cases.) */
357   if (strcmp(e->class, strtrim(class)) &&
358       strcmp(class, "STAFF") && strcmp(class, "SIPBMEM") &&
359       strcmp(class, "KNIGHT"))
360     {
361       com_err(whoami, 0, "updating class for %s %s from %s to %s",
362               first, last, class, e->class);
363       if (status == US_NOT_ALLOWED)
364         status = US_NO_LOGIN_YET;
365       if (status == US_ENROLL_NOT_ALLOWED)
366         status = US_ENROLLED;
367       strcpy(class, e->class);
368       if (!debug)
369         {
370           EXEC SQL UPDATE users
371             SET type = NVL(:class, CHR(0)), status = :status,
372             modtime = SYSDATE, modby = :who, modwith = :prog
373             WHERE users_id = :id;
374           if (sqlca.sqlcode)
375             {
376               dbmserr("updating user", sqlca.sqlcode);
377               exit(1);
378             }
379         }
380     }
381
382   /* Update name if necessary */
383   if (strcmp(first, strtrim(dfirst)) ||
384       strcmp(last, strtrim(dlast)) ||
385       strcmp(middle, strtrim(dmiddle)))
386     {
387       com_err(whoami, 0, "updating real name for %s %s", first, last);
388       if (!debug)
389         {
390           EXEC SQL UPDATE users
391             SET first = NVL(:first, CHR(0)), last = NVL(:last, CHR(0)),
392             middle = NVL(:middle, CHR(0)), modby = :who, modwith = :prog,
393             modtime = SYSDATE
394             WHERE users_id = :id;
395           if (sqlca.sqlcode)
396             {
397               dbmserr("updating name", sqlca.sqlcode);
398               exit(1);
399             }
400         }
401       else
402         {
403           com_err(whoami, 0, "was %s %s %s, became %s %s %s",
404                   dfirst, dmiddle, dlast, first, middle, last);
405         }
406     }
407
408   changed = nochange = 0;
409   strcpy(buf, e->address);
410   while ((to = strchr(buf, ',')))
411     *to = ';';
412   while ((to = strchr(buf, ':')))
413     *to = ';';
414   if (newfinger)
415     {
416       if (oaddr[0] == ' ' && buf[0])
417         {
418           strncpy(oaddr, buf, USERS_OFFICE_ADDR_SIZE - 1);
419           oaddr[USERS_OFFICE_ADDR_SIZE - 1] = '\0';
420           changed++;
421         }
422       else if (strncmp(strtrim(oaddr), buf, USERS_OFFICE_ADDR_SIZE - 1))
423         nochange++;
424     }
425   else
426     {
427       if (strncmp(strtrim(oaddr), buf, USERS_OFFICE_ADDR_SIZE - 1))
428         {
429           changed++;
430           if (debug)
431             {
432               com_err(whoami, 0, "office for %s %s changed from %s to %s",
433                       first, last, oaddr, buf);
434             }
435         }
436       strncpy(oaddr, buf, USERS_OFFICE_ADDR_SIZE - 1);
437       oaddr[USERS_OFFICE_ADDR_SIZE - 1] = '\0';
438     }
439   from = e->phone;
440   to = buf;
441   while (*from)
442     {
443       if (isdigit(*from))
444         *to++ = *from;
445       from++;
446     }
447   *to = '\0';
448   if (newfinger)
449     {
450       if (ophone[0] == ' ')
451         {
452           strncpy(ophone, buf, USERS_OFFICE_PHONE_SIZE - 1);
453           ophone[USERS_OFFICE_PHONE_SIZE - 1] = '\0';
454         }
455       else if (strncmp(strtrim(ophone), buf, USERS_OFFICE_PHONE_SIZE - 1))
456         nochange++;
457     }
458   else
459     {
460       if (strncmp(strtrim(ophone), buf, USERS_OFFICE_PHONE_SIZE - 1))
461         {
462           changed++;
463           if (debug)
464             {
465               com_err(whoami, 0, "Phone for %s %s changed from %s to %s",
466                       first, last, ophone, buf);
467             }
468         }
469       strncpy(ophone, buf, USERS_OFFICE_PHONE_SIZE - 1);
470       ophone[USERS_OFFICE_PHONE_SIZE - 1] = '\0';
471     }
472   FixCase(e->dept);
473   FixCase(e->title);
474   if (newfinger)
475     {
476       if (dept[0] == ' ')
477         {
478           strncpy(dept, e->dept, USERS_DEPARTMENT_SIZE - 1);
479           dept[USERS_DEPARTMENT_SIZE - 1] = '\0';
480         }
481       else if (strncmp(strtrim(dept), e->dept, USERS_DEPARTMENT_SIZE - 1))
482         nochange++;
483     }
484   else
485     {
486       if (strncmp(strtrim(dept), e->dept, USERS_DEPARTMENT_SIZE - 1))
487         {
488           changed++;
489           if (debug)
490             {
491               com_err(whoami, 0, "Department for %s %s changed from %s to %s",
492                       first, last, dept, e->dept);
493             }
494         }
495       strncpy(dept, e->dept, USERS_DEPARTMENT_SIZE - 1);
496       dept[USERS_DEPARTMENT_SIZE - 1] = '\0';
497     }
498   sid = e->id;
499   name = e->name;
500   rdept = e->dept;
501   rtitle = e->title;
502   raddr = e->address;
503   rhphone = e->phone;
504   rophone = e->phone2;
505
506   if (debug)
507     return;
508
509   if (changed)
510     {
511       com_err(whoami, 0, "updating finger for %s %s", first, last);
512       EXEC SQL UPDATE users
513         SET office_addr = NVL(:oaddr, CHR(0)),
514         office_phone = NVL(:ophone, CHR(0)), department = NVL(:dept, CHR(0)),
515         fmodtime = SYSDATE, fmodby = :who, fmodwith = :prog,
516         xname = NVL(:name, CHR(0)), xdept = NVL(:rdept, CHR(0)),
517         xtitle = NVL(:rtitle, CHR(0)), xaddress = NVL(:raddr, CHR(0)),
518         xphone1 = NVL(:rhphone, CHR(0)), xphone2 = NVL(:rophone, CHR(0)),
519         xmodtime = SYSDATE, clearid = NVL(:sid, CHR(0))
520         WHERE users_id = :id;
521       if (sqlca.sqlcode)
522         {
523           dbmserr(NULL, sqlca.sqlcode);
524           exit(1);
525         }
526     }
527   else
528     {
529       EXEC SQL UPDATE users
530         SET xname = NVL(:name, CHR(0)), xdept = NVL(:rdept, CHR(0)),
531         xtitle = NVL(:rtitle, CHR(0)), xaddress = NVL(:raddr, CHR(0)),
532         xphone1 = NVL(:rhphone, CHR(0)), xphone2 = NVL(:rophone, CHR(0)),
533         xmodtime = SYSDATE, clearid = NVL(:sid, CHR(0))
534         WHERE users_id = :id;
535       if (sqlca.sqlcode)
536         {
537           dbmserr(NULL, sqlca.sqlcode);
538           exit(1);
539         }
540     }
541 }
542
543
544 void newuser(struct entry *e)
545 {
546   char *from, *to;
547   EXEC SQL BEGIN DECLARE SECTION;
548   int id, uid, st, who;
549   char *last, *first, *class, *middle, login[USERS_LOGIN_SIZE], *sid;
550   char fullname[USERS_FULLNAME_SIZE], *prog;
551   char oaddr[USERS_OFFICE_ADDR_SIZE], ophone[USERS_OFFICE_PHONE_SIZE];
552   char dept[USERS_DEPARTMENT_SIZE], *name, *title;
553   char *rdept, *rhphone, *rophone;
554   EXEC SQL END DECLARE SECTION;
555
556   who = WHO;
557   prog = PROG;
558   strncpy(oaddr, e->address, USERS_OFFICE_ADDR_SIZE - 1);
559   oaddr[USERS_OFFICE_ADDR_SIZE - 1] = '\0';
560   while ((to = strchr(oaddr, ',')))
561     *to = ';';
562   while ((to = strchr(oaddr, ':')))
563     *to = ';';
564   from = e->phone;
565   to = ophone;
566   while (*from)
567     {
568       if (isdigit(*from))
569         *to++ = *from;
570       from++;
571     }
572   *to = '\0';
573   FixCase(e->dept);
574   strncpy(dept, e->dept, USERS_DEPARTMENT_SIZE - 1);
575   dept[USERS_DEPARTMENT_SIZE - 1] = '\0';
576
577   id = set_next_users_id(0);
578   uid = set_next_uid(e->highid);
579   sprintf(login, "#%d", uid);
580   last = e->last;
581   first = e->first;
582   middle = e->middle;
583   class = e->class;
584   if (*middle)
585     sprintf(fullname, "%s %s %s", first, middle, last);
586   else
587     sprintf(fullname, "%s %s", first, last);
588   st = US_NO_LOGIN_YET;
589
590   sid = e->id;
591   name = e->name;
592   rdept = e->dept;
593   title = e->title;
594   rhphone = e->phone;
595   rophone = e->phone2;
596
597   com_err(whoami, 0, "adding user %s %s", e->first, e->last);
598   if (debug)
599     return;
600
601   EXEC SQL INSERT INTO users
602     (login, users_id, unix_uid, shell, last, first, middle, status,
603      clearid, type, modtime, modby, modwith, fullname, office_addr,
604      office_phone, department, fmodtime, fmodby, fmodwith,
605      potype, xname, xdept, xtitle, xaddress, xphone1, xphone2, xmodtime)
606     VALUES (:login, :id, :uid, '/bin/athena/tcsh',
607             NVL(:last, CHR(0)), NVL(:first, CHR(0)), NVL(:middle, CHR(0)),
608             :st, NVL(:sid, CHR(0)), NVL(:class, CHR(0)), SYSDATE, :who, :prog,
609             NVL(:fullname, CHR(0)), NVL(:oaddr, CHR(0)), NVL(:ophone, CHR(0)),
610             NVL(:dept, CHR(0)), SYSDATE, :who, :prog, 'NONE',
611             NVL(:name, CHR(0)), NVL(:rdept, CHR(0)), NVL(:title, CHR(0)),
612             NVL(:oaddr, CHR(0)), NVL(:rhphone, CHR(0)), NVL(:rophone, CHR(0)),
613             SYSDATE);
614   if (sqlca.sqlcode)
615     {
616       dbmserr("adding user", sqlca.sqlcode);
617       exit(1);
618     }
619 }
620
621
622 int set_next_users_id(int limit)
623 {
624   EXEC SQL BEGIN DECLARE SECTION;
625   int flag, value, retval;
626   EXEC SQL END DECLARE SECTION;
627
628   if (debug)
629     return 0;
630
631   EXEC SQL SELECT value INTO :value FROM numvalues
632     WHERE name = 'users_id';
633   if (sqlfail())
634     sqlexit();
635   if (sqlca.sqlerrd[2] != 1)
636     {
637       EXEC SQL ROLLBACK;
638       com_err(whoami, MR_INTERNAL, "values table inconsistancy");
639       exit(1);
640     }
641
642   flag = 0;
643   EXEC SQL SELECT users_id INTO :flag FROM users
644     WHERE users_id = :value;
645   if (sqlfail())
646     sqlexit();
647   if (sqlca.sqlerrd[2] == 0)
648     flag = 0;
649   while (flag)
650     {
651       value++;
652       if (limit && value > MAX_ID_VALUE)
653         value = MIN_ID_VALUE;
654       flag = 0;
655       EXEC SQL SELECT users_id INTO :flag FROM users
656         WHERE users_id = :value;
657       if (sqlfail())
658         sqlexit();
659       if (sqlca.sqlerrd[2] == 0)
660         flag = 0;
661     }
662
663   retval = value++;
664   if (limit && value > MAX_ID_VALUE)
665     value = MIN_ID_VALUE;
666   EXEC SQL UPDATE numvalues SET value = :value
667     WHERE name = 'users_id';
668   if (sqlca.sqlcode)
669     {
670       dbmserr("assigning ID", sqlca.sqlcode);
671       exit(1);
672     }
673   return retval;
674 }
675
676 int set_next_uid(int high)
677 {
678   EXEC SQL BEGIN DECLARE SECTION;
679   int flag, initial, value, retval;
680   char *name;
681   EXEC SQL END DECLARE SECTION;
682
683   if (debug)
684     return 0;
685
686   if (high)
687     name = "high_uid";
688   else
689     name = "unix_uid";
690
691   EXEC SQL SELECT value INTO :initial FROM numvalues
692     WHERE name = :name;
693   if (sqlfail())
694     sqlexit();
695   if (sqlca.sqlerrd[2] != 1)
696     {
697       EXEC SQL ROLLBACK;
698       com_err(whoami, MR_INTERNAL, "values table inconsistancy");
699       exit(1);
700     }
701
702   value = initial;
703   flag = 0;
704   EXEC SQL SELECT COUNT(unix_uid) INTO :flag
705     FROM users WHERE unix_uid = :value;
706   if (sqlfail())
707     sqlexit();
708   while (flag)
709     {
710       value++;
711       if (!high && value > MAX_ID_VALUE)
712         value = MIN_ID_VALUE;
713       if (value == initial)
714         {
715           com_err(whoami, 0, "Out of uids!");
716           EXEC SQL ROLLBACK WORK;
717           exit(1);
718         }
719       flag = 0;
720       EXEC SQL SELECT COUNT(unix_uid) INTO :flag
721         FROM users WHERE unix_uid = :value;
722       if (sqlfail())
723         sqlexit();
724     }
725
726   retval = value++;
727   if (!high && value > MAX_ID_VALUE)
728     value = MIN_ID_VALUE;
729   EXEC SQL UPDATE numvalues SET value = :value WHERE name = :name;
730   if (sqlca.sqlcode)
731     {
732       dbmserr("assigning ID", sqlca.sqlcode);
733       exit(1);
734     }
735   return retval;
736 }
737
738
739 void sqlexit(void)
740 {
741   dbmserr(NULL, sqlca.sqlcode);
742   EXEC SQL ROLLBACK WORK;
743   exit(1);
744 }
745
746 void dbmserr(char *where, int what)
747 {
748   char err_msg[256];
749   int bufsize = 256, msglength = 0;
750
751   sqlglm(err_msg, &bufsize, &msglength);
752   err_msg[msglength] = '\0';
753
754   if (where)
755     com_err(whoami, 0, "DBMS error %swhile %s", err_msg, where);
756   else
757     com_err(whoami, 0, "DBMS error %s", err_msg);
758 }
This page took 2.790989 seconds and 5 git commands to generate.