]> andersk Git - moira.git/blobdiff - dbck/dbck.dc
DBMS=ORACLE
[moira.git] / dbck / dbck.dc
index 5595702aa521627a777270b88c12e21a99f6d1f5..4c644ef336c8e55fab284337cd36d3987386a712 100644 (file)
@@ -12,7 +12,8 @@
 #include <strings.h>
 #include <signal.h>
 #include "dbck.h"
-
+EXEC SQL INCLUDE sqlca;
+EXEC SQL INCLUDE sqlda;
 
 static char dbck_qc_rcsid[] = "$Header$";
 
@@ -21,12 +22,15 @@ 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, *string_dups;
+EXEC SQL BEGIN DECLARE SECTION; 
+int dcmenable;
+EXEC SQL END DECLARE SECTION; 
 struct save_queue *modtables, *sq_create();
-int interrupt();
+void interrupt();
+SQLDA *mr_sqlda;
 
 
 main(argc, argv)
@@ -34,11 +38,14 @@ 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";
+    setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
 
     while (++arg - argv < argc) {
        if  (**arg == '-')
@@ -88,73 +95,84 @@ char **argv;
     if (debug)
       printf("Debug level is %d\n", debug);
 
-    setlinebuf(stdout);
-
     signal(SIGHUP, interrupt);
     signal(SIGQUIT, interrupt);
     signal(SIGINT, interrupt);
+
     modtables = sq_create();
+    mr_sqlda = sqlald(1, 255, 0);
 
-    IIseterr(ingerr);
+    EXEC SQL WHENEVER SQLERROR DO dbmserr();
     printf("Opening database %s...", database);
     fflush(stdout);
-##  ingres database
+    EXEC SQL CONNECT :database IDENTIFIED BY :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();
+    EXEC SQL COMMIT WORK;
 
-##  end transaction
     cleanup();
     printf("Done.\n");
     exit(0);
 }
 
-ingerr(num)
-int    *num;
+dbmserr()
 {
-    printf("An ingres error occuurred, code %d\n", *num);
+EXEC SQL BEGIN DECLARE SECTION;
+    char buf[512];
+EXEC SQL END DECLARE SECTION;
+    int bufsize=256, msglength=0;
+
+    if (sqlca.sqlcode==1403) return;
+    printf("A DBMS error occurred, code %d\n", sqlca.sqlcode);
+    sqlglm(buf, &bufsize, &msglength);
+    buf[msglength]=0;
+    printf("%s\n", buf);
     printf("Aborting...\n");
-    if (!abort) {
-       abort++;
-##     abort
+    if (!abort_p) {
+       abort_p++;
+       EXEC SQL ROLLBACK WORK;
     }
     exit(1);
 }
 
 
-int interrupt()
-##{
+void 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++;
-       /* break out of a retrieve loop */
-       IIbreak();
-##     abort
+    if (!abort_p) {
+       abort_p++;
+       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 +182,30 @@ 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 UPDATE tblstats SET modtime=SYSDATE
+           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")) {
+       EXEC SQL COMMIT WORK;
+       cleanup();
+       exit(1);
+    }
+    printf("Aborting transaction\n");
+    EXEC SQL ROLLBACK WORK;
     exit(1);
 }
This page took 0.038519 seconds and 4 git commands to generate.