3 * Moira database consistency checker
5 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
15 EXEC SQL INCLUDE sqlca;
16 EXEC SQL INCLUDE sqlda;
18 static char dbck_qc_rcsid[] = "$Header$";
26 struct hash *users, *machines, *clusters, *lists, *filesys, *nfsphys;
27 struct hash *strings, *members, *subnets, *string_dups;
28 EXEC SQL BEGIN DECLARE SECTION;
30 EXEC SQL END DECLARE SECTION;
31 struct save_queue *modtables, *sq_create();
35 extern SQLDA *sqlald(int,int,int);
42 EXEC SQL BEGIN DECLARE SECTION;
44 EXEC SQL END DECLARE SECTION;
49 setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
51 while (++arg - argv < argc) {
55 debug = atoi((*arg)[2] ? *arg+2 : *++arg);
79 printf("Usage: %s [-d level] [-n] [-y] [-p] [-a] [-c] [-f] [-w] [database]\n",
87 printf("Only doing counts\n");
89 printf("Doing fast version (skipping some checks)\n");
91 printf("Will NOT modify the database\n");
92 else if (mode == MODE_PREEN)
93 printf("Will fix simple things without asking\n");
94 else if (mode == MODE_YES)
95 printf("Will fix everything without asking\n");
97 printf("Debug level is %d\n", debug);
99 signal(SIGHUP, interrupt);
100 signal(SIGQUIT, interrupt);
101 signal(SIGINT, interrupt);
103 modtables = sq_create();
104 mr_sqlda = sqlald(1, 255, 0);
106 EXEC SQL WHENEVER SQLERROR DO dbmserr();
107 printf("Opening database %s...", database);
109 EXEC SQL CONNECT :database IDENTIFIED BY :database;
111 EXEC SQL SELECT value INTO :dcmenable FROM numvalues
112 WHERE name='dcm_enable';
113 dprintf("DCM disabled (was %d)\n", dcmenable);
114 EXEC SQL UPDATE numvalues SET value=0 WHERE name='dcm_enable';
116 /* Begin transaction here. */
120 EXEC SQL COMMIT WORK;
122 EXEC SQL COMMIT WORK;
124 EXEC SQL COMMIT WORK;
127 EXEC SQL COMMIT WORK;
130 EXEC SQL COMMIT WORK;
139 EXEC SQL BEGIN DECLARE SECTION;
141 EXEC SQL END DECLARE SECTION;
142 int bufsize=256, msglength=0;
144 if (sqlca.sqlcode==1403) return;
145 printf("A DBMS error occurred, code %d\n", sqlca.sqlcode);
146 sqlglm(buf, &bufsize, &msglength);
149 printf("Aborting...\n");
152 EXEC SQL ROLLBACK WORK;
160 printf("Signal caught\n");
161 if (prompt("Save database changes")) {
162 EXEC SQL COMMIT WORK;
166 printf("Aborting transaction\n");
169 EXEC SQL ROLLBACK WORK;
172 EXEC SQL UPDATE numvalues SET value=:dcmenable
173 WHERE name='dcm_enable';
182 sq_save_unique_string(modtables, table);
187 EXEC SQL BEGIN DECLARE SECTION;
189 EXEC SQL END DECLARE SECTION;
191 while (sq_get_data(modtables, &tab)) {
192 EXEC SQL UPDATE tblstats SET modtime=SYSDATE
193 WHERE table_name = :tab;
195 EXEC SQL UPDATE numvalues SET value = :dcmenable
196 WHERE name='dcm_enable';
203 fprintf(stderr, "Out of memory while %s\n", msg);
204 if (prompt("Save database changes")) {
205 EXEC SQL COMMIT WORK;
209 printf("Aborting transaction\n");
210 EXEC SQL ROLLBACK WORK;