]> andersk Git - moira.git/blobdiff - dbck/dbck.dc
increase machine name length
[moira.git] / dbck / dbck.dc
index 5595702aa521627a777270b88c12e21a99f6d1f5..525d567a181e81ecd875e41c5bb13bdd7fb5ba52 100644 (file)
@@ -21,10 +21,12 @@ int debug = 0;
 int mode = MODE_ASK;
 int fast = 0;
 int warn = 1;
-int abort = 0;
+int abort_p = 0;
 struct hash *users, *machines, *clusters, *lists, *filesys, *nfsphys;
-struct hash *strings, *members;
-##int dcmenable;
+struct hash *strings, *members, *subnets;
+EXEC SQL BEGIN DECLARE SECTION; 
+int dcmenable;
+EXEC SQL END DECLARE SECTION; 
 struct save_queue *modtables, *sq_create();
 int interrupt();
 
@@ -34,11 +36,13 @@ int argc;
 char **argv;
 {
     char **arg = argv;
-##  char *database;
+EXEC SQL BEGIN DECLARE SECTION; 
+    char *database;
+EXEC SQL END DECLARE SECTION; 
     int ingerr();
     int countonly = 0;
 
-    database = "sms";
+    database = "moira";
 
     while (++arg - argv < argc) {
        if  (**arg == '-')
@@ -98,24 +102,30 @@ char **argv;
     IIseterr(ingerr);
     printf("Opening database %s...", database);
     fflush(stdout);
-##  ingres database
+    EXEC SQL CONNECT :database;
     printf("done\n");
-##  retrieve (dcmenable = values.value) where values.name = "dcm_enable"
+    EXEC SQL SELECT value INTO :dcmenable FROM numvalues 
+       WHERE name='dcm_enable'; 
     dprintf("DCM disabled (was %d)\n", dcmenable);
-##  replace values (value = 0) where values.name = "dcm_enable"
+    EXEC SQL UPDATE numvalues SET value=0 WHERE name='dcm_enable';
 
-##  begin transaction
+    /* Begin transaction here. */
 
     if (!countonly) {
        phase1();
+       EXEC SQL COMMIT WORK;
        phase2();
+       EXEC SQL COMMIT WORK;
        phase3();
+       EXEC SQL COMMIT WORK;
     } else {
        count_only_setup();
+       EXEC SQL COMMIT WORK;
     }
     phase4();
 
-##  end transaction
+    EXEC SQL COMMIT WORK;
+
     cleanup();
     printf("Done.\n");
     exit(0);
@@ -124,37 +134,41 @@ char **argv;
 ingerr(num)
 int    *num;
 {
+    if (*num == 100) return;
     printf("An ingres error occuurred, code %d\n", *num);
     printf("Aborting...\n");
-    if (!abort) {
-       abort++;
-##     abort
+    if (!abort_p) {
+       abort_p++;
+       EXEC SQL ROLLBACK WORK;
     }
     exit(1);
 }
 
 
 int interrupt()
-##{
+{
     printf("Signal caught\n");
     if (prompt("Save database changes")) {
        /* break out of a retrieve loop */
        IIbreak();
-##     end transaction
+
+       EXEC SQL COMMIT WORK;
        cleanup();
        exit(0);
     }
     printf("Aborting transaction\n");
-    if (!abort) {
-       abort++;
+    if (!abort_p) {
+       abort_p++;
        /* break out of a retrieve loop */
        IIbreak();
-##     abort
+       EXEC SQL ROLLBACK WORK;
     }
-##  replace values (value = dcmenable) where values.name = "dcm_enable"
-##  exit
+
+    EXEC SQL UPDATE numvalues SET value=:dcmenable
+       WHERE name='dcm_enable';
+
     exit(0);
-##}
+}
 
 
 modified(table)
@@ -164,22 +178,34 @@ char *table;
 }
 
 cleanup()
-##{
-##  char *tab;
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    char *tab;
+    EXEC SQL END DECLARE SECTION; 
 
     while (sq_get_data(modtables, &tab)) {
-##     replace tblstats (modtime = "now") where tblstats.table = tab
+       EXEC SQL REPEATED UPDATE tblstats SET modtime='now'
+           WHERE table_name = :tab;
     }
-##  replace values (value = dcmenable) where values.name = "dcm_enable"
-##  exit
-##}
+    EXEC SQL UPDATE numvalues SET value = :dcmenable
+       WHERE name='dcm_enable';
+}
 
 
 out_of_mem(msg)
 char *msg;
 {
     fprintf(stderr, "Out of memory while %s\n", msg);
-##  end transaction    
-    cleanup();
+    if (prompt("Save database changes")) {
+       /* break out of a retrieve loop */
+       IIbreak();
+
+       EXEC SQL COMMIT WORK;
+       cleanup();
+       exit(1);
+    }
+    printf("Aborting transaction\n");
+    IIbreak();
+    EXEC SQL ROLLBACK WORK;
     exit(1);
 }
This page took 0.039954 seconds and 4 git commands to generate.