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;
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();
40 EXEC SQL BEGIN DECLARE SECTION;
42 EXEC SQL END DECLARE SECTION;
48 while (++arg - argv < argc) {
52 debug = atoi((*arg)[2] ? *arg+2 : *++arg);
76 printf("Usage: %s [-d level] [-n] [-y] [-p] [-a] [-c] [-f] [-w] [database]\n",
84 printf("Only doing counts\n");
86 printf("Doing fast version (skipping some checks)\n");
88 printf("Will NOT modify the database\n");
89 else if (mode == MODE_PREEN)
90 printf("Will fix simple things without asking\n");
91 else if (mode == MODE_YES)
92 printf("Will fix everything without asking\n");
94 printf("Debug level is %d\n", debug);
98 signal(SIGHUP, interrupt);
99 signal(SIGQUIT, interrupt);
100 signal(SIGINT, interrupt);
101 modtables = sq_create();
104 printf("Opening database %s...", database);
106 EXEC SQL CONNECT :database;
108 EXEC SQL SELECT value INTO :dcmenable FROM numvalues
109 WHERE name='dcm_enable';
110 dprintf("DCM disabled (was %d)\n", dcmenable);
111 EXEC SQL UPDATE numvalues SET value=0 WHERE name='dcm_enable';
113 /* Begin transaction here. */
117 EXEC SQL COMMIT WORK;
119 EXEC SQL COMMIT WORK;
121 EXEC SQL COMMIT WORK;
124 EXEC SQL COMMIT WORK;
127 EXEC SQL COMMIT WORK;
137 EXEC SQL BEGIN DECLARE SECTION;
139 EXEC SQL END DECLARE SECTION;
141 if (*num == 100) return;
142 printf("An ingres error occurred, code %d\n", *num);
143 EXEC SQL INQUIRE_SQL(:buf = errortext);
145 printf("Aborting...\n");
148 EXEC SQL ROLLBACK WORK;
156 printf("Signal caught\n");
157 if (prompt("Save database changes")) {
158 /* break out of a retrieve loop */
161 EXEC SQL COMMIT WORK;
165 printf("Aborting transaction\n");
168 /* break out of a retrieve loop */
170 EXEC SQL ROLLBACK WORK;
173 EXEC SQL UPDATE numvalues SET value=:dcmenable
174 WHERE name='dcm_enable';
183 sq_save_unique_string(modtables, table);
188 EXEC SQL BEGIN DECLARE SECTION;
190 EXEC SQL END DECLARE SECTION;
192 while (sq_get_data(modtables, &tab)) {
193 EXEC SQL REPEATED UPDATE tblstats SET modtime='now'
194 WHERE table_name = :tab;
196 EXEC SQL UPDATE numvalues SET value = :dcmenable
197 WHERE name='dcm_enable';
204 fprintf(stderr, "Out of memory while %s\n", msg);
205 if (prompt("Save database changes")) {
206 /* break out of a retrieve loop */
209 EXEC SQL COMMIT WORK;
213 printf("Aborting transaction\n");
215 EXEC SQL ROLLBACK WORK;