3 * This generates a database extract from the users table for the MIT
6 * Copyright (C) 1996-1998 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
13 #include <moira_site.h>
16 #include <sys/types.h>
29 EXEC SQL INCLUDE sqlca;
33 char *whoami = "warehouse.gen";
34 char *db = "moira/moira";
36 #ifndef WAREHOUSE_SUBDIR
37 #define WAREHOUSE_SUBDIR "warehouse"
40 char warehouse_dir[MAXPATHLEN];
42 int main(int argc, char **argv)
44 int out = STDOUT_FILENO;
45 char *outf = NULL, outft[MAXPATHLEN];
46 char control_fn[MAXPATHLEN], cmd[256];
49 EXEC SQL BEGIN DECLARE SECTION;
50 char login[USERS_LOGIN_SIZE];
51 char id[USERS_CLEARID_SIZE], kname[MAX_K_NAME_SZ];
52 char fname[USERS_FIRST_SIZE], lname[USERS_LAST_SIZE];
53 char middle[USERS_MIDDLE_SIZE];
63 EXEC SQL END DECLARE SECTION;
65 initialize_sms_error_table();
67 sprintf(warehouse_dir, "%s/%s", DCM_DIR, WAREHOUSE_SUBDIR);
74 sprintf(outft, "%s/username_id.map", warehouse_dir);
75 if ((out = open(outft, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, 0666)) < 0)
77 fprintf(stderr, "unable to open %s for output\n", outf);
83 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
89 /* The following is declarative, not executed,
90 * and so is dependent on where it is in the file,
91 * not in the order of execution of statements.
93 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
95 EXEC SQL DECLARE x CURSOR FOR
96 SELECT login, clearid, first, last, middle
98 WHERE (status = 1 or status = 2 or status = 5 OR
99 status = 6 or status = 7 or status = 9);
103 EXEC SQL FETCH x INTO :login, :id, :fname, :lname, :middle;
115 memset(&outrec, 0, sizeof(outrec));
116 strcpy(outrec.login, login);
117 strcpy(outrec.id, id);
118 strcpy(outrec.fname, fname);
119 strcpy(outrec.lname, lname);
120 strcpy(outrec.middle, middle);
121 write(out, &outrec, sizeof(outrec));
130 perror("close failed");
133 sprintf(control_fn, "%s/username_id.ctl", warehouse_dir);
135 f = fopen(control_fn, "w");
138 perror("creating username_id control file");
141 fprintf(f, "username_id.map --- Moira feed for MIT Data Warehouse\n");
142 fprintf(f, "%d records\n", records);
143 fprintf(f, "%d bytes\n", records * (12 + 12 + 20 + 20 + 20 + 256));
144 fprintf(f, "Full feed\n");
145 fprintf(f, "Fixed format -- binary\n");
149 fprintf(stderr, "Building tar file.\n");
150 sprintf(cmd, "(cd %s; tar cf - . ) | compress > %s",
151 warehouse_dir, outf);
159 db_error(sqlca.sqlcode);