]> andersk Git - moira.git/commitdiff
SQL port completed.
authorgenoa <genoa>
Tue, 12 Jan 1993 22:11:20 +0000 (22:11 +0000)
committergenoa <genoa>
Tue, 12 Jan 1993 22:11:20 +0000 (22:11 +0000)
dbck/dbck.dc
dbck/fix.dc
dbck/phase1.dc
dbck/phase2.dc
dbck/phase3.dc
dbck/phase4.dc

index 5595702aa521627a777270b88c12e21a99f6d1f5..12a214b33a66b7fdaced6192a919f2a6e8ad9cd6 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;
+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,13 +102,17 @@ char **argv;
     IIseterr(ingerr);
     printf("Opening database %s...", database);
     fflush(stdout);
-##  ingres database
+/*  ingres database */
+    EXEC SQL CONNECT :database;
     printf("done\n");
-##  retrieve (dcmenable = values.value) where values.name = "dcm_enable"
+/*  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"
+/*  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();
@@ -115,7 +123,8 @@ char **argv;
     }
     phase4();
 
-##  end transaction
+    EXEC SQL COMMIT WORK;
+
     cleanup();
     printf("Done.\n");
     exit(0);
@@ -126,35 +135,41 @@ int       *num;
 {
     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
+
+/*  replace values (value = dcmenable) where values.name = "dcm_enable" */
+    EXEC SQL UPDATE numvalues SET value=:dcmenable
+       WHERE name='dcm_enable';
+
+/*  exit */
+    /* No equivalent (?) */
     exit(0);
-##}
+}
 
 
 modified(table)
@@ -164,22 +179,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
+/*     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
-##}
+/*  replace values (value = dcmenable) where values.name = "dcm_enable" */
+    EXEC SQL UPDATE numvalues SET value = :dcmenable
+       WHERE name='dcm_enable';
+/*  exit */
+    /* No equivalent (?) */
+}
 
 
 out_of_mem(msg)
 char *msg;
 {
     fprintf(stderr, "Out of memory while %s\n", msg);
-##  end transaction    
+/*  end transaction    */
+    EXEC SQL COMMIT WORK;
     cleanup();
     exit(1);
 }
index 6a05e78f8fd248cf9c61285f59a4d6125c03c471..7ae6785d053f46708b3633e9feaa70603e0eff80 100644 (file)
 #include <stdio.h>
 #include "dbck.h"
 
-static char fix_qc_rcsid[] = "$Header$";
+EXEC SQL INCLUDE sqlca;  /* SQL Communications Area */
+EXEC SQL INCLUDE sqlda;  /* SQL Descriptor Area */
+
+#define SQLDA_RETVALS
+typedef IISQLDA_TYPE(DBCK_SQLDA,DBCK_SQLDA_T,SQLDA_RETVALS);
+DBCK_SQLDA_T SQLDA;
 
+static char fix_qc_rcsid[] = "$Header$";
 
-##char *_table;
-##char *_idfield;
+EXEC SQL BEGIN DECLARE SECTION; 
+char *_table;
+char *_idfield;
+char stmt_buf[500];
+EXEC SQL END DECLARE SECTION; 
 
-##generic_ffunc(id)
-##int id;
-##{
-##  int rowcount;
+generic_ffunc(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount;
+    EXEC SQL END DECLARE SECTION; 
 
-##  delete _table where _table._idfield = id
-##  inquire_equel(rowcount = "rowcount")
+/*  delete _table where _table._idfield = id */
+    sprintf(stmt_buf,"DELETE FROM %s WHERE %s.%s = %d",
+           _table,_table,_idfield,id);
+    EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
+/*  inquire_equel(rowcount = "rowcount") */
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount > 0)
       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not deleted\n");
     modified(_table);
-##}
+}
 
 
 generic_delete(sq, pfunc, table, idfield, preen)
@@ -55,20 +72,28 @@ int id;
 }
 
 
-##zero_fix(table, zrfield, idfield, id)
-##char *table, *zrfield, *idfield;
-##int id;
-##{
-##  int rowcount;
+zero_fix(tbl, zrfield, idfield, id)
+EXEC SQL BEGIN DECLARE SECTION; 
+char *tbl, *zrfield, *idfield;
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount;
+    EXEC SQL END DECLARE SECTION; 
 
-##  replace table (zrfield = 0) where table.idfield = id
-##  inquire_equel(rowcount = "rowcount")
+/*  replace tbl (zrfield = 0) where table.idfield = id */
+    sprintf(stmt_buf,"UPDATE %s SET %d = 0 WHERE %s.%s = %d",
+           tbl,zrfield,tbl,idfield,id);
+    EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
+/*  inquire_equel(rowcount = "rowcount") */
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount > 0)
       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not fixed\n");
-    modified(table);
-##}
+    modified(tbl);
+}
 
 
 int single_fix(msg, preen)
@@ -112,7 +137,9 @@ int prompt(msg)
 char *msg;
 {
     char buf[BUFSIZ];
-##  extern int dcmenable;
+    EXEC SQL BEGIN DECLARE SECTION; 
+    extern int dcmenable;
+    EXEC SQL END DECLARE SECTION; 
 
     while (1) {
        printf("%s (Y/N/Q)? ", msg);
@@ -125,14 +152,19 @@ char *msg;
        if (buf[0] == 'Q' || buf[0] == 'q') {
            if (prompt("Are you sure you want to quit")) {
                if (prompt("Save database changes")) {
-##                 end transaction
+/*                 end transaction */
+                   EXEC SQL COMMIT WORK;
                    cleanup();
                    exit(0);
                } else {
-##                 abort
-##                 replace values (value = dcmenable)
-##                     where values.name = "dcm_enable"
-##                 exit
+/*                 abort */
+                   EXEC SQL ROLLBACK WORK;
+/*                 replace values (value = dcmenable)
+ *                     where values.name = "dcm_enable" */
+                   EXEC SQL UPDATE numvalues SET value = :dcmenable
+                       WHERE name='dcm_enable';
+/*                 exit */
+                   /* No equivalent (?) */
                    exit(1);
                }
            }
@@ -152,57 +184,96 @@ char *msg;
  **
  **/
 
-int set_next_object_id(object, table)
+int set_next_object_id(object, tablename)
     char *object;
-    char *table;
-##{
-##  char *name, *tbl;
-##  int rowcount, exists, value;
+    char *tablename;
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    char *name, *tbl;
+    int rowcount, existence, value;
+    EXEC SQL END DECLARE SECTION; 
 
     name = object;
-    tbl = table;
-##  range of v is values
-##  repeat retrieve (value = v.#value) where v.#name = @name
-##  inquire_equel(rowcount = "rowcount")
+    tbl = tablename;
+/*  range of v is values
+ *  repeat retrieve (value = v.#value) where v.#name = @name */
+    EXEC SQL REPEATED SELECT value INTO :value FROM numvalues
+       WHERE name = :name;
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount != 1)
        return(MR_NO_ID);
 
-##  retrieve (exists = any(tbl.name where tbl.name = value))
-##  inquire_equel(rowcount = "rowcount")
+/*  retrieve (existence = any(tbl.name where tbl.name = value)) */
+    SQLDA.sqlvar[0].sqldata=(void *)&rowcount;
+    sprintf(stmt_buf,"SELECT COUNT (*) FROM %s WHERE %s=%d",tbl,name,value);
+    EXEC SQL PREPARE stmt INTO :&SQLDA USING NAMES FROM :stmt_buf; 
+    if(sqlca.sqlcode)
+       return(MR_INTERNAL);
+    EXEC SQL DECLARE foo CURSOR FOR stmt;
+    EXEC SQL OPEN foo;
+    EXEC SQL FETCH foo USING DESCRIPTOR :&SQLDA;
+    if (sqlca.sqlcode < 0) return(MR_INTERNAL);
+    if (sqlca.sqlcode == 100) existence=0; else existence=1;
+    EXEC SQL CLOSE foo;
+
     if (rowcount != 1)
        return(MR_NO_ID);
-    while (exists) {
+    while (existence) {
        value++;
        if (value > MAX_ID_VALUE)
            value = MIN_ID_VALUE;
-##     retrieve (exists = any(tbl.name where tbl.name = value))
+/*     retrieve (existence = any(tbl.name where tbl.name = value)) */
+       sprintf(stmt_buf,"SELECT %s FROM %s WHERE %s=%d",name,tbl,name,value);
+       EXEC SQL PREPARE stmt INTO :&SQLDA USING NAMES FROM :stmt_buf; 
+       if(sqlca.sqlcode)
+           return(MR_INTERNAL);
+       EXEC SQL DECLARE bar CURSOR FOR stmt;
+       EXEC SQL OPEN bar;
+       EXEC SQL FETCH bar USING DESCRIPTOR :&SQLDA;
+       if (sqlca.sqlcode != 0) break;
+       EXEC SQL CLOSE bar;
     }
+    EXEC SQL CLOSE bar; 
 
     printf("setting ID %s to %d\n", name, value);
-##  repeat replace v (#value = @value) where v.#name = @name
+/*  repeat replace v (#value = @value) where v.#name = @name */
+    EXEC SQL REPEATED UPDATE numvalues SET value = :value
+       WHERE name = :name;
     modified("values");
     return(MR_SUCCESS);
-##}
-
-
-##generic_fix_id(table, idfield, txtfield, oldid, name)
-##char *table;
-##char *idfield;
-##char *txtfield;
-##int oldid;
-##char *name;
-##{
-##  int rowcount, id;
-
-    set_next_object_id(table, idfield);
-##  retrieve (id = values.value) where values.#name = idfield
-##  replace table (idfield = values.value) where values.#name = idfield and
-##     table.idfield = oldid and table.txtfield = name
-##  inquire_equel(rowcount = "rowcount")
+}
+
+
+generic_fix_id(tbl, idfield, txtfield, oldid, name)
+    EXEC SQL BEGIN DECLARE SECTION; 
+    char *tbl;
+    char *idfield;
+    char *txtfield;
+    int oldid;
+    char *name;
+    EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount, id, temp;
+    EXEC SQL END DECLARE SECTION; 
+
+    set_next_object_id(tbl, idfield);
+/*  retrieve (id = values.value) where values.#name = idfield */
+    EXEC SQL SELECT value INTO :id FROM numvalues
+       WHERE name = :idfield;
+/*  replace tbl (idfield = values.value) where values.#name = idfield and
+ *     tbl.idfield = oldid and tbl.txtfield = name
+ */
+    EXEC SQL SELECT value INTO :temp FROM numvalues 
+       WHERE name = :idfield;
+    sprintf(stmt_buf,"UPDATE %s SET %s = %d WHERE %s=%d AND %s='%s'",
+           tbl,idfield,temp,idfield,oldid,txtfield,name);
+    EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount == 1)
       printf("Fixed\n");
     else
       printf("Not fixed, rowcount = %d\n", rowcount);
-    modified(table);
+    modified(tbl);
     return(id);
-##}
+}
index a5e0e692f5c48143504a42606a13fd13e35e5703..d2474ad61ac99b669771672f58d121682b4a4038 100644 (file)
@@ -8,6 +8,8 @@
 #include <mit-copyright.h>
 #include <moira.h>
 #include "dbck.h"
+EXEC SQL INCLUDE sqlca;
+
 
 static char phase1_qc_rcsid[] = "$Header$";
 
@@ -26,7 +28,8 @@ struct save_queue *sq;
     struct user *u, *uu, *tmp;
 
     uu = (struct user *)0;
-    while (sq_get_data(sq, &u)) {
+    if(sq_get_data(sq,&uu)) {
+      while (sq_get_data(sq, &u)) {
        if (!strcmp(u->login, uu->login)) {
            if (uu->status == 1 || u->status == 0) {
                tmp = u;
@@ -41,21 +44,26 @@ struct save_queue *sq;
                single_fix("Delete the second one")) {
                single_delete("users", "users_id", uu->users_id);
            } else if (single_fix("Unregister the second one"))
-##           {
-##             int id = uu->users_id, rowcount;
-
-##             replace users (login = "#"+text(users.uid), status = 0)
-##                 where users.users_id = id
-##             inquire_equel(rowcount = "rowcount")
+             {
+               EXEC SQL BEGIN DECLARE SECTION; 
+               int id = uu->users_id, rowcount;
+               EXEC SQL END DECLARE SECTION; 
+
+/*             replace users (login = "#"+text(users.uid), status = 0)
+ *                 where users.users_id = id */
+               EXEC SQL UPDATE users SET login = '#'+CHAR(users.uid),
+                   status=0 WHERE users_id = :id;
+               EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
                if (rowcount > 0)
                  printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
                else
                  printf("Not fixed\n");
                modified("users");
-##         }
+             }
        } else {
            uu = u;
        }
+      }
     }
 }
 
@@ -174,9 +182,11 @@ struct string *s;
 
 
 phase1()
-##{
-##  char name[81], name1[81], last[17], first[17], buf[257];
-##  int id, id2, id3, aid, aid2, status, sid, sid2, sid3, sid4, sid5;
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    char name[81], name1[81], last[17], first[17], buf[257];
+    int id, id2, id3, aid, aid2, status, sid, sid2, sid3, sid4, sid5;
+    EXEC SQL END DECLARE SECTION; 
     struct save_queue *sq;
     struct user *u;
     struct machine *m;
@@ -191,8 +201,16 @@ phase1()
     dprintf("Loading strings...\n");
     sq = sq_create();
     strings = create_hash(5000);
-##  range of s is strings
-##  retrieve (id = s.string_id, buf = s.string) {
+/*  range of s is strings 
+ *  retrieve (id = s.string_id, buf = s.string) { 
+ */
+    EXEC SQL DECLARE csr101 CURSOR FOR
+      SELECT string_id, string FROM strings;
+    EXEC SQL OPEN csr101;
+    while(1) {
+       EXEC SQL FETCH csr101 INTO :id, :buf;
+       if(sqlca.sqlcode != 0) break;
+
        s = (struct string *) malloc(sizeof(struct string));
        if (s == NULL)
          out_of_mem("storing strings");
@@ -203,18 +221,29 @@ phase1()
            sq_save_data(sq, hash_lookup(strings, id));
            sq_save_data(sq, s);
        }
-##  }
+    }
+    EXEC SQL CLOSE csr101;
     generic_delete(sq, show_str_id, "strings", "string_id", 0);
     string_check(0);
 
     dprintf("Loading users...\n");
     sq = sq_create();
     users = create_hash(10000);
-##  range of u is users
-##  retrieve (id = u.users_id, name = u.login, last = u.#last,
-##           first = u.#first, status = u.#status, buf = u.potype,
-##           id2 = u.pop_id, id3 = u.box_id, sid = u.modby, sid2 = u.fmodby,
-##           sid3 = u.pmodby, sid4 = u.comment, sid5 = u.sigwho) {
+/*  range of u is users
+ *  retrieve (id = u.users_id, name = u.login, last = u.#last,
+ *           first = u.#first, status = u.#status, buf = u.potype,
+ *           id2 = u.pop_id, id3 = u.box_id, sid = u.modby, sid2 = u.fmodby,
+ *           sid3 = u.pmodby, sid4 = u.comment, sid5 = u.sigwho) {
+ */
+    EXEC SQL DECLARE csr102 CURSOR FOR 
+      SELECT users_id, login, last, first, status, potype, pop_id, box_id,
+         modby, fmodby, pmodby, comment, sigwho FROM users;
+    EXEC SQL OPEN csr102;
+    while(1) {
+       EXEC SQL FETCH csr102 INTO :id, :name, :last, :first, :status,
+            :buf, :id2, :id3, :sid, :sid2, :sid3, :sid4, :sid5;
+       if(sqlca.sqlcode != 0) break;
+
        u = (struct user *) malloc(sizeof(struct user));
        if (u == NULL)
          out_of_mem("storing users");
@@ -248,23 +277,41 @@ phase1()
          string_check(sid4);
        if (sid5)
          string_check(sid5);
-##  }
+    }
+    EXEC SQL CLOSE csr102; 
+
     generic_fix(sq, show_user_id, "Change ID", fix_user_id, 0);
 
     if (!fast) {
        sq = sq_create();
-##     retrieve (id = u.users_id)
-##         where u.login = users.login and u.tid != users.tid {
-         sq_save_data(sq, hash_lookup(users, id));
-##     }
+/*     retrieve (id = u.users_id)
+ *         where u.login = users.login and u.tid != users.tid {
+ */
+       EXEC SQL DECLARE csr103 CURSOR FOR 
+           SELECT users_id FROM users;
+       EXEC SQL OPEN csr103;
+       while(1) {
+           EXEC SQL FETCH csr103 INTO :id;
+           if(sqlca.sqlcode != 0) break;
+           sq_save_data(sq, hash_lookup(users, id));
+       }
+       EXEC SQL CLOSE csr103; 
        handle_duplicate_logins(sq);
     }
 
     dprintf("Loading machines...\n");
     machines = create_hash(1000);
     sq = sq_create();
-##  range of m is machine
-##  retrieve (id = m.mach_id, name = m.#name, sid = m.modby) {
+/*  range of m is machine
+ *  retrieve (id = m.mach_id, name = m.#name, sid = m.modby) {
+ */
+    EXEC SQL DECLARE csr104 CURSOR FOR
+       SELECT mach_id, name, modby FROM machine;
+    EXEC SQL OPEN csr104;
+    while(1) {
+       EXEC SQL FETCH csr104 INTO :id, :name, :sid;
+       if(sqlca.sqlcode != 0) break; 
+
        m = (struct machine *) malloc(sizeof(struct machine));
        if (m == NULL)
          out_of_mem("storing machines");
@@ -277,23 +324,42 @@ phase1()
        }
        if (sid < 0)
          string_check(-sid);
-##  }
+    }
+    EXEC SQL CLOSE csr104; 
     generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0);
 
     if (!fast) {
        sq = sq_create();
-##     retrieve (id = m.mach_id)
-##         where m.#name = machine.#name and m.tid != machine.tid {
-         sq_save_data(sq, hash_lookup(machines, id));
-##     }
+/*     retrieve (id = m.mach_id)
+ *         where m.#name = machine.#name and m.tid != machine.tid {
+ */
+       EXEC SQL DECLARE csr105 CURSOR FOR
+           SELECT m1.mach_id FROM machine m1, machine m2
+               WHERE m1.name = m2.name AND m1.tid != m2.tid;
+       EXEC SQL OPEN csr105;
+       while(1) {
+           EXEC SQL FETCH csr105 INTO :id;
+           if(sqlca.sqlcode != 0) break; 
+
+           sq_save_data(sq, hash_lookup(machines, id));
+       }
+       EXEC SQL CLOSE csr105; 
        generic_fix(sq, show_mach_name, "Change name", cant_fix, 0);
     }  
 
     dprintf("Loading clusters...\n");
     sq = sq_create();
     clusters = create_hash(100);
-##  range of c is cluster
-##  retrieve (id = c.clu_id, name = c.#name, sid = c.modby) {
+/*  range of c is cluster
+ *  retrieve (id = c.clu_id, name = c.#name, sid = c.modby) {
+ */
+    EXEC SQL DECLARE csr106 CURSOR FOR
+       SELECT clu_id, name, modby FROM cluster;
+    EXEC SQL OPEN csr106;
+    while(1) {
+       EXEC SQL FETCH csr106 INTO :id, :name, :sid;
+       if(sqlca.sqlcode != 0) break; 
+
        c = (struct cluster *) malloc(sizeof(struct cluster));
        if (c == NULL)
          out_of_mem("storing clusters");
@@ -305,24 +371,42 @@ phase1()
        }
        if (sid < 0)
          string_check(-sid);
-##  }
+    }
+    EXEC SQL CLOSE csr106; 
     generic_fix(sq, show_clu_id, "Change ID", fix_clu_id, 0);
 
     if (!fast) {
        sq = sq_create();
-##     retrieve (id = c.clu_id)
-##         where c.#name = cluster.#name and c.tid != cluster.tid {
-         sq_save_data(sq, hash_lookup(clusters, id));
-##     }
+/*     retrieve (id = c.clu_id)
+ *         where c.#name = cluster.#name and c.tid != cluster.tid {
+ */
+       EXEC SQL DECLARE csr107 CURSOR FOR
+           SELECT clu_id FROM cluster c1, cluster c2
+               WHERE c1.name=c2.name AND c1.tid != c2.tid;
+       EXEC SQL OPEN csr107;
+       while(1) {
+           EXEC SQL FETCH csr107 INTO :id;
+           if(sqlca.sqlcode != 0) break; 
+
+           sq_save_data(sq, hash_lookup(clusters, id));
+       }
+       EXEC SQL CLOSE csr107; 
        generic_fix(sq, show_clu_name, "Change name", cant_fix, 0);
     }
 
     dprintf("Loading lists...\n");
     sq = sq_create();
     lists = create_hash(10000);
-##  range of l is list
-##  retrieve (id = l.list_id, name = l.#name,
-##           aid = l.acl_id, buf = l.acl_type, sid = l.modby) {
+/*  range of l is list
+ *  retrieve (id = l.list_id, name = l.#name,
+ *           aid = l.acl_id, buf = l.acl_type, sid = l.modby) {
+ */
+    EXEC SQL DECLARE csr108 CURSOR FOR
+       SELECT list_id, name, acl_id, acl_type, modby  FROM list;
+    EXEC SQL OPEN csr108;
+    while(1) {
+       EXEC SQL FETCH csr108 INTO :id, :name, :aid, :buf, :sid;
+       if(sqlca.sqlcode != 0) break;                                                               
        l = (struct list *) malloc(sizeof(struct list));
        if (l == NULL)
          out_of_mem("storing lists");
@@ -337,25 +421,46 @@ phase1()
        }
        if (sid < 0)
          string_check(-sid);
-##  }
+    }
+    EXEC SQL CLOSE csr108; 
     generic_fix(sq, show_list_id, "Change ID", fix_list_id, 0);
 
     if (!fast) {
        sq = sq_create();
-##     retrieve (id = l.list_id)
-##         where l.#name = list.#name and l.tid != list.tid {
-         sq_save_data(sq, hash_lookup(lists, id));
-##     }
+/*     retrieve (id = l.list_id)
+ *         where l.#name = list.#name and l.tid != list.tid {
+ */
+       EXEC SQL DECLARE csr109 CURSOR FOR
+           SELECT list_id FROM list l1, list l2
+               WHERE l1.name=l2.name AND l1.tid != l2.tid;
+       EXEC SQL OPEN csr109;
+       while(1) {
+           EXEC SQL FETCH csr109 INTO :id;
+           if(sqlca.sqlcode != 0) break; 
+           
+           sq_save_data(sq, hash_lookup(lists, id));
+       }
+       EXEC SQL CLOSE csr109;
        generic_fix(sq, show_list_name, "Change name", cant_fix, 0);
     }
 
     dprintf("Loading filesys...\n");
     sq = sq_create();
     filesys = create_hash(10000);
-##  retrieve (id = filesys.filsys_id, name = filesys.label, aid = filesys.owner,
-##           aid2 = filesys.owners, id2 = filesys.phys_id,
-##           id3 = filesys.mach_id, buf = filesys.type,
-##           name1 = filesys.#name, sid = filesys.modby) {
+/*  retrieve (id = filesys.filsys_id, name = filesys.label, aid = filesys.owner,
+ *           aid2 = filesys.owners, id2 = filesys.phys_id,
+ *           id3 = filesys.mach_id, buf = filesys.type,
+ *           name1 = filesys.#name, sid = filesys.modby) {
+ */
+    EXEC SQL DECLARE csr110 CURSOR FOR
+       SELECT filsys_id, label, owner, owners, phys_id, mach_id,
+               type, name, modby FROM filesys;
+    EXEC SQL OPEN csr110;
+    while(1) {
+       EXEC SQL FETCH csr110 INTO :id, :name, :aid, :aid2, :id2, :id3, 
+           :buf, :name1, :sid;
+       if(sqlca.sqlcode != 0) break;
+
        f = (struct filesys *) malloc(sizeof(struct filesys));
        if (f == NULL)
          out_of_mem("storing filesystems");
@@ -373,15 +478,25 @@ phase1()
        }
        if (sid < 0)
          string_check(-sid);
-##  }
+    }
+    EXEC SQL CLOSE csr110;
+
     generic_fix(sq, show_fs_id, "Change ID", fix_fs_id, 0);
 
     dprintf("Loading nfsphys...\n");
     sq = sq_create();
     nfsphys = create_hash(500);
-##  retrieve (id = nfsphys.nfsphys_id, name = nfsphys.dir,
-##           id2 = nfsphys.mach_id, id3 = nfsphys.allocated,
-##           sid = nfsphys.modby) {
+/*  retrieve (id = nfsphys.nfsphys_id, name = nfsphys.dir,
+ *           id2 = nfsphys.mach_id, id3 = nfsphys.allocated,
+ *           sid = nfsphys.modby) {
+ */
+    EXEC SQL DECLARE csr111 CURSOR FOR
+       SELECT nfsphys_id, dir, mach_id, allocated, modby FROM nfsphys;
+    EXEC SQL OPEN csr111;
+    while(1) {
+       EXEC SQL FETCH csr111 INTO :id, :name, :id2, :id3, :sid;
+       if(sqlca.sqlcode != 0) break; 
+
        n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
        if (n == NULL)
          out_of_mem("storing nfsphys");
@@ -396,31 +511,63 @@ phase1()
        }
        if (sid < 0)
          string_check(-sid);
-##  }
+    }
+    EXEC SQL CLOSE csr111;
+
     generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0);
 
     if (!fast) {
-##     range of s is strings
-##     retrieve (id = s.string_id, buf = s.string)
-##         where s.string = strings.string and s.tid != strings.tid {
-         printf("String %s(%d) is a duplicate!\n", strtrim(buf), id);
-         printf("Not fixing this error\n");
-##     }
+/*     range of s is strings
+ *     retrieve (id = s.string_id, buf = s.string)
+ *         where s.string = strings.string and s.tid != strings.tid {
+ */
+       EXEC SQL DECLARE csr112 CURSOR FOR
+           SELECT s1.string_id, s1.string FROM strings s1, strings s2
+               WHERE s1.string=s2.string AND s1.tid != s2.tid;
+       EXEC SQL OPEN csr112;
+       while(1) {
+           EXEC SQL FETCH csr112 INTO :id, :buf;
+           if(sqlca.sqlcode != 0) break; 
+
+           printf("String %s(%d) is a duplicate!\n", strtrim(buf), id);
+           printf("Not fixing this error\n");
+       }
+       EXEC SQL CLOSE csr112;
     }
 
     if (!fast) {
        dprintf("Scanning krbmap...\n");
-##     range of k is krbmap
-##     retrieve (id = k.users_id)
-##         where k.users_id = krbmap.users_id and k.tid != krbmap.tid {
-         printf("User %d is in the krbmap more than once!\n", id);
-         printf("Not fixing this error\n");
-##     }
-##     retrieve (id = k.string_id)
-##         where k.string_id = krbmap.string_id and k.tid != krbmap.tid {
-         printf("Principal %d is in the krbmap more than once!\n", id);
-         printf("Not fixing this error\n");
-##     }
-    }
-##}
+/*     range of k is krbmap
+ *     retrieve (id = k.users_id)
+ *         where k.users_id = krbmap.users_id and k.tid != krbmap.tid {
+ */
+       EXEC SQL DECLARE csr113 CURSOR FOR
+           SELECT k1.users_id FROM krbmap k1, krbmap k2
+               WHERE k1.users_id = k2.users_id AND k1.tid != k2.tid;
+       EXEC SQL OPEN csr113;
+       while(1) {
+           EXEC SQL FETCH csr113 INTO :id;
+           if(sqlca.sqlcode != 0) break; 
+
+           printf("User %d is in the krbmap more than once!\n", id);
+           printf("Not fixing this error\n");
+       }
+       EXEC SQL CLOSE csr113; 
 
+/*     retrieve (id = k.string_id)
+ *         where k.string_id = krbmap.string_id and k.tid != krbmap.tid {
+ */
+       EXEC SQL DECLARE csr114 CURSOR FOR
+           SELECT k1.string_id FROM krbmap k1, krbmap k2
+               WHERE k1.string_id = k2.string_id AND k1.tid != k2.tid;
+       EXEC SQL OPEN csr114;
+       while(1) {
+           EXEC SQL FETCH csr114 INTO :id;
+           if(sqlca.sqlcode != 0) break; 
+
+           printf("Principal %d is in the krbmap more than once!\n", id);
+           printf("Not fixing this error\n");
+       }
+       EXEC SQL CLOSE csr114; 
+    }
+}
index 9a0840d650199d2c6e76ac972fb0a4f42f8e8dc9..2164ebe57b2e87655ab87f2c28a3547ffb3aeb5b 100644 (file)
@@ -9,39 +9,62 @@
 #include <stdio.h>
 #include <moira.h>
 #include "dbck.h"
+EXEC SQL INCLUDE sqlca;
 
 static char phase2_qc_rcsid[] = "$Header$";
 
 
 show_mcm_mach(id)
 int id;
-##{
-##  int iid = id, found = 1;
-##  char name[33];
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int iid = id, found = 1;
+    char name[33];
+    EXEC SQL END DECLARE SECTION; 
+
+/*  retrieve (name = cluster.#name) where cluster.clu_id = mcmap.clu_id
+ *     and mcmap.mach_id = iid { */
+    EXEC SQL DECLARE csr201 CURSOR FOR
+      SELECT cluster.name FROM cluster, mcmap
+        WHERE cluster.clu_id=mcmap.clu_id AND mcmap.mach_id = :iid;
+    EXEC SQL OPEN csr201;
+    while(1) {
+       EXEC SQL FETCH csr201 INTO :name;
+       if(sqlca.sqlcode != 0) break; 
 
-##  retrieve (name = cluster.#name) where cluster.clu_id = mcmap.clu_id
-##     and mcmap.mach_id = iid {
-      strtrim(name);
-      found = 0;
-      printf("Cluster %s, non-existant machine %d in cluster map\n", name, id);
-##  }
+       strtrim(name);
+       found = 0;
+       printf("Clusqter %s, non-existant machine %d in cluster map\n", name, id);
+    }
+    EXEC SQL CLOSE csr201; 
     return(found);
-##}
+}
 
 show_mcm_clu(id)
 int id;
-##{
-##  int iid = id, found = 1;
-##  char name[33];
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int iid = id, found = 1;
+    char name[33];
+    EXEC SQL END DECLARE SECTION; 
+
+/*  retrieve (name = machine.#name) where machine.mach_id = mcmap.mach_id
+ *     and mcmap.clu_id = iid { */
+    EXEC SQL DECLARE csr202 CURSOR FOR
+       SELECT machine.name FROM machine, mcmap
+           WHERE machine.mach_id=mcmap.mach_id AND mcmap.clu_id=:iid;
+    EXEC SQL OPEN csr202;
+    while(1) {
+       EXEC SQL FETCH csr202 INTO :name;
+       if(sqlca.sqlcode != 0) break; 
 
-##  retrieve (name = machine.#name) where machine.mach_id = mcmap.mach_id
-##     and mcmap.clu_id = iid {
-      strtrim(name);
-      found = 0;
-      printf("Machine %s, non-existant cluster %d in cluster map\n", name, id);
-##  }
+       strtrim(name);
+       found = 0;
+       printf("Machine %s, non-existant cluster %d in cluster map\n", name, id);
+    }
+    EXEC SQL CLOSE csr202; 
     return(found);
-##}
+}
 
 pobox_check(id, u, hint)
 int id;
@@ -77,33 +100,47 @@ int hint;
 
 remove_pobox(id)
 int id;
-##{
-##  int rowcount, iid = id;
-##  replace users (potype = "NONE") where users.users_id = iid
-##  inquire_equel(rowcount = "rowcount")
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount, iid = id;
+    EXEC SQL END DECLARE SECTION; 
+/*  replace users (potype = "NONE") where users.users_id = iid */
+    EXEC SQL UPDATE users SET potype='NONE' WHERE users.users_id = :iid;
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
     if (rowcount > 0)
       printf("%d entr%s removed\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not removed\n");
     modified("users");
-##}
+}
 
 show_svc(id)
 int id;
-##{
-##  int iid = id, found = 1;
-##  char label[17], data[33];
-
-##  retrieve (label = svc.serv_label, data = svc.serv_cluster) 
-##     where svc.clu_id = iid {
-      strtrim(label);
-      strtrim(data);
-      found = 0;
-      printf("Cluster data [%s] %s for non-existant cluster %d\n",
-            label, data, id);
-##  }
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int iid = id, found = 1;
+    char label[17], data[33];
+    EXEC SQL END DECLARE SECTION; 
+
+/*  retrieve (label = svc.serv_label, data = svc.serv_cluster) 
+ *     where svc.clu_id = iid {  */
+    EXEC SQL DECLARE csr203 CURSOR FOR
+       SELECT serv_label, serv_cluster FROM svc
+           WHERE clu_id = :iid;
+    EXEC SQL OPEN csr203;
+    while(1) {
+       EXEC SQL FETCH csr203 INTO :label, :data;
+       if(sqlca.sqlcode != 0) break;                               
+
+       strtrim(label);
+       strtrim(data);
+       found = 0;
+       printf("Cluster data [%s] %s for non-existant cluster %d\n",
+              label, data, id);
+    }
+    EXEC SQL CLOSE csr203; 
     return(found);
-##}
+}
 
 list_check(id, l, hint)
 int id;
@@ -132,194 +169,296 @@ int hint;
 
 fix_list_acl(id)
 int id;
-##{
-##  int rowcount, iid = id;
-##  replace list (acl_id = iid, acl_type = "LIST") where list.list_id = iid
-##  inquire_equel(rowcount = "rowcount")
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount, iid = id;
+    EXEC SQL END DECLARE SECTION; 
+
+/*  replace list (acl_id = iid, acl_type = "LIST") where list.list_id = iid */
+    EXEC SQL UPDATE list SET acl_id = :iid, acl_type='LIST'
+       WHERE list_id = :iid;
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount > 0)
       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not fixed\n");
     modified("list");
-##}
+}
 
 
 show_member_list(id)
 int id;
-##{
-##  int mid, iid = id, found = 1;
-##  char mtype[9], *name = "";
-
-##  retrieve (mtype = imembers.member_type, mid = imembers.member_id)
-##     where imembers.list_id = iid and imembers.direct = 1 {
-      strtrim(mtype);
-      found = 0;
-      if (mtype[0] == 'L')
-       name = ((struct list *) hash_lookup(lists, mid))->name;
-      else if (mtype[0] == 'U')
-       name = ((struct user *) hash_lookup(users, mid))->login;
-      else if (mtype[0] == 'S' || mtype[0] == 'K')
-       name = ((struct string *) hash_lookup(strings, mid))->name;
-      printf("Non-existant list %d has member %s %s\n", iid, mtype, name);
-##  }
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int mid, iid = id, found = 1;
+    char mtype[9], *name = "";
+    EXEC SQL END DECLARE SECTION;
+
+/*  retrieve (mtype = imembers.member_type, mid = imembers.member_id)
+ *     where imembers.list_id = iid and imembers.direct = 1 { */
+    EXEC SQL DECLARE csr204 CURSOR FOR
+       SELECT member_type, member_id FROM imembers
+           WHERE list_id = :iid AND direct=1;
+    EXEC SQL OPEN csr204;
+    while(1) {
+       EXEC SQL FETCH csr204 INTO :mtype, :mid;
+       if(sqlca.sqlcode != 0) break; 
+
+       strtrim(mtype);
+       found = 0;
+       if (mtype[0] == 'L')
+           name = ((struct list *) hash_lookup(lists, mid))->name;
+       else if (mtype[0] == 'U')
+           name = ((struct user *) hash_lookup(users, mid))->login;
+       else if (mtype[0] == 'S' || mtype[0] == 'K')
+           name = ((struct string *) hash_lookup(strings, mid))->name;
+       printf("Non-existant list %d has member %s %s\n", iid, mtype, name);
+    }
+    EXEC SQL CLOSE csr204; 
     return(found);
-##}
+}
 
 show_mem_user(id)
 int id;
-##{
-##  int lid, iid = id, found = 1;
-##  char name[33];
-
-##  retrieve (lid = imembers.list_id)
-##     where imembers.member_id = iid and imembers.member_type = "USER" and
-##           imembers.direct = 1 {
-      found = 0;
-      printf("List %s has non-existant user member, id %d\n",
-            ((struct list *)hash_lookup(lists, lid))->name, iid);
-##  }
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int lid, iid = id, found = 1;
+    char name[33];
+    EXEC SQL END DECLARE SECTION; 
+
+/*  retrieve (lid = imembers.list_id)
+ *     where imembers.member_id = iid and imembers.member_type = "USER" and
+ *           imembers.direct = 1 { */
+    EXEC SQL DECLARE csr205 CURSOR FOR
+      SELECT list_id FROM imembers
+       WHERE member_id = :iid AND member_type='USER' AND direct=1;
+    EXEC SQL OPEN csr205;
+    while(1) {
+       EXEC SQL FETCH csr205 INTO :lid;
+       if(sqlca.sqlcode != 0) break;   
+       
+       found = 0;
+       printf("List %s has non-existant user member, id %d\n",
+              ((struct list *)hash_lookup(lists, lid))->name, iid);
+    }
+    EXEC SQL CLOSE csr205;
     return(found);
-##}
+}
 
 show_mem_list(id)
 int id;
-##{
-##  int lid, iid = id, found = 1;
-##  char name[33];
-
-##  retrieve (lid = imembers.list_id)
-##     where imembers.member_id = iid and imembers.member_type = "LIST" and
-##           imembers.direct = 1 {
-      found = 0;
-      printf("List %s has non-existant list member, id %d\n",
-            ((struct list *)hash_lookup(lists, lid))->name, iid);
-##  }
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int lid, iid = id, found = 1;
+    char name[33];
+    EXEC SQL END DECLARE SECTION; 
+
+/*  retrieve (lid = imembers.list_id)
+ *     where imembers.member_id = iid and imembers.member_type = "LIST" and
+ *           imembers.direct = 1 { */
+    EXEC SQL DECLARE csr206 CURSOR FOR
+       SELECT list_id FROM imembers
+           WHERE member_id = :iid AND member_type='LIST' AND direct=1;
+    EXEC SQL OPEN csr206;
+    while(1) {
+       EXEC SQL FETCH csr206 INTO :lid;
+       if(sqlca.sqlcode != 0) break; 
+
+       found = 0;
+       printf("List %s has non-existant list member, id %d\n",
+              ((struct list *)hash_lookup(lists, lid))->name, iid);
+    }
+    EXEC SQL CLOSE csr206; 
     return(found);
-##}
+}
 
 show_mem_str(id)
 int id;
-##{
-##  int lid, iid = id, found = 1;
-##  char name[33];
-
-##  retrieve (lid = imembers.list_id)
-##     where imembers.member_id = iid and imembers.member_type = "STRING" and
-##           imembers.direct = 1 {
-      found = 0;
-      printf("List %s has non-existant string member, id %d\n",
-            ((struct list *)hash_lookup(lists, lid))->name, iid);
-##  }
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int lid, iid = id, found = 1;
+    char name[33];
+    EXEC SQL END DECLARE SECTION; 
+
+/*  retrieve (lid = imembers.list_id)
+ *     where imembers.member_id = iid and imembers.member_type = "STRING" and
+ *           imembers.direct = 1 { */
+    EXEC SQL DECLARE csr207 CURSOR FOR
+       SELECT list_id FROM imembers
+           WHERE member_id = :iid AND member_type='STRING' AND direct=1;
+    EXEC SQL OPEN csr207;
+    while(1) {
+       EXEC SQL FETCH csr207 INTO :lid;
+       if(sqlca.sqlcode != 0) break; 
+       
+       found = 0;
+       printf("List %s has non-existant string member, id %d\n",
+              ((struct list *)hash_lookup(lists, lid))->name, iid);
+    }
+    EXEC SQL CLOSE csr207; 
     return(found);
-##}
+}
 
 
 show_mem_krb(id)
 int id;
-##{
-##  int lid, iid = id, found = 1;
-##  char name[33];
-
-##  retrieve (lid = imembers.list_id)
-##     where imembers.member_id = iid and imembers.member_type = "KERBEROS" and
-##           imembers.direct = 1 {
-      found = 0;
-      printf("List %s has non-existant kerberos member, id %d\n",
-            ((struct list *)hash_lookup(lists, lid))->name, iid);
-##  }
-    return(found);
-##}
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int lid, iid = id, found = 1;
+    char name[33];
+    EXEC SQL END DECLARE SECTION; 
+
+/*  retrieve (lid = imembers.list_id)
+ *     where imembers.member_id = iid and imembers.member_type = "KERBEROS" and
+ *           imembers.direct = 1 { */
+    EXEC SQL DECLARE csr208 CURSOR FOR
+       SELECT list_id FROM imembers
+           WHERE member_id = :iid AND member_type='KERBEROS' AND direct=1;
+    EXEC SQL OPEN csr208;
+    while(1) {
+       EXEC SQL FETCH csr208 INTO :lid;
+       if(sqlca.sqlcode != 0) break; 
 
+       found = 0;
+       printf("List %s has non-existant kerberos member, id %d\n",
+              ((struct list *)hash_lookup(lists, lid))->name, iid);
+    }
+    EXEC SQL CLOSE csr208; 
+    return(found);
+}
 
-##del_mem_user(id)
-##int id;
-##{
-##  int rowcount;
 
-##  delete imembers where imembers.member_type = "USER" and
-##     imembers.member_id = id and imembers.direct = 1
-##  inquire_equel(rowcount = "rowcount");
+del_mem_user(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount;
+    EXEC SQL END DECLARE SECTION; 
+
+/*  delete imembers where imembers.member_type = "USER" and
+ *     imembers.member_id = id and imembers.direct = 1 */
+    EXEC SQL DELETE FROM imembers WHERE member_type='USER' AND
+       member_id = :id AND direct = 1;
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount > 0)
       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not deleted\n");
     modified("imembers");
-##}
-
-##del_mem_list(id)
-##int id;
-##{
-##  int rowcount;
+}
 
-##  delete imembers where imembers.member_type = "LIST" and
-##     imembers.member_id = id and imembers.direct = 1
-##  inquire_equel(rowcount = "rowcount");
+del_mem_list(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount;
+    EXEC SQL END DECLARE SECTION; 
+
+/*  delete imembers where imembers.member_type = "LIST" and
+ *     imembers.member_id = id and imembers.direct = 1 */
+    EXEC SQL DELETE FROM imembers WHERE member_type='LIST' AND
+       member_id = :id AND direct=1;
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount > 0)
       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not deleted\n");
     modified("imembers");
-##}
-
-##del_mem_str(id)
-##int id;
-##{
-##  int rowcount;
+}
 
-##  delete imembers where imembers.member_type = "STRING" and
-##     imembers.member_id = id and imembers.direct = 1
-##  inquire_equel(rowcount = "rowcount");
+del_mem_str(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount;
+    EXEC SQL END DECLARE SECTION; 
+
+/*  delete imembers where imembers.member_type = "STRING" and
+ *     imembers.member_id = id and imembers.direct = 1 */
+    EXEC SQL DELETE FROM imembers WHERE member_type='STRING' AND
+       member_id = :id AND direct=1;
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount > 0)
       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not deleted\n");
     modified("imembers");
-##}
-
+}
 
-##del_mem_krb(id)
-##int id;
-##{
-##  int rowcount;
 
-##  delete imembers where imembers.member_type = "KERBEROS" and
-##     imembers.member_id = id and imembers.direct = 1
-##  inquire_equel(rowcount = "rowcount");
+del_mem_krb(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount;
+    EXEC SQL END DECLARE SECTION; 
+
+/*  delete imembers where imembers.member_type = "KERBEROS" and
+ *     imembers.member_id = id and imembers.direct = 1 */
+    EXEC SQL DELETE FROM imembers WHERE member_type='KERBEROS' AND
+       member_id = :id AND direct=1;
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount > 0)
       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not deleted\n");
     modified("imembers");
-##}
+}
 
 
-##show_sh(id)
-##int id;
-##{
-##  char name[33];
+show_sh(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    char name[33];
+    EXEC SQL END DECLARE SECTION; 
     int found = 1;
 
-##  retrieve (name = serverhosts.service) where serverhosts.mach_id = id {
-      found = 0;
-      printf("ServerHost entry for service %s non-existant host %d\n",
-            name, id);
-##  }
+/*  retrieve (name = serverhosts.service) where serverhosts.mach_id = id { */
+    EXEC SQL DECLARE csr209 CURSOR FOR
+       SELECT service FROM serverhosts
+           WHERE mach_id = :id;
+    EXEC SQL OPEN csr209;
+    while(1) {
+       EXEC SQL FETCH csr209 INTO :name;
+       if(sqlca.sqlcode != 0) break; 
+
+       found = 0;
+       printf("ServerHost entry for service %s non-existant host %d\n",
+              name, id);
+    }
+    EXEC SQL CLOSE csr209; 
     return(found);
-##}
+}
 
-##del_sh_mach(id)
-##int id;
-##{
-##  int rowcount;
+del_sh_mach(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount;
+    EXEC SQL END DECLARE SECTION; 
 
-##  delete serverhosts where serverhosts.mach_id = id
-##  inquire_equel(rowcount = "rowcount");
+/*  delete serverhosts where serverhosts.mach_id = id */
+    EXEC SQL DELETE FROM serverhosts WHERE mach_id = :id;
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount > 0)
       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not deleted\n");
     modified("serverhosts");
-##}
+}
 
 
 static int fnchecklen;
@@ -338,21 +477,26 @@ struct filesys *f;
 }
 
 
-##check_fs(id, f, hint)
-##int id;
+check_fs(id, f, hint)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
 register struct filesys *f;
 int hint;
-##{
-##  int id1, id2, id3, rowcount;
-##  char *dir;
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int id1, id2, id3, rowcount;
+    char *dir;
+    EXEC SQL END DECLARE SECTION; 
     struct nfsphys *n;
     struct machine *m;
 
     if (!hash_lookup(machines, f->mach_id)) {
        printf("Filesys %s with bad machine %d\n", f->name, f->mach_id);
        if (single_fix("Fix", 0)) {
-##         replace filesys (mach_id = 0) where filesys.filsys_id = id
-##         inquire_equel(rowcount = "rowcount")
+/*         replace filesys (mach_id = 0) where filesys.filsys_id = id */
+           EXEC SQL UPDATE filesys SET mach_id = 0 WHERE filsys_id = :id;
+           EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
            if (rowcount > 0)
              printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
            else
@@ -388,8 +532,9 @@ int hint;
                  id1 = f->phys_id;
                  id2 = f->filsys_id;
                  id3 = f->mach_id;
-##               replace filesys (phys_id = id1) where filesys.filsys_id = id2
-##               inquire_equel(rowcount = "rowcount")
+/*               replace filesys (phys_id = id1) where filesys.filsys_id = id2 */
+                 EXEC SQL UPDATE filesys SET phys_id = :id1 WHERE filsys_id = :id2;
+                 EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
                  if (rowcount > 0)
                    printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
                  else
@@ -407,19 +552,27 @@ int hint;
                            printf("Unable to assign unique ID\n");
                            return;
                        }
-##                     retrieve (id1 = values.value)
-##                       where values.name = "nfsphys_id"
-##                     inquire_equel(rowcount = "rowcount")
+/*                     retrieve (id1 = values.value)
+ *                       where values.name = "nfsphys_id"
+ *                     inquire_equel(rowcount = "rowcount")
+ */
+                       EXEC SQL SELECT COUNT(*) INTO :rowcount FROM numvalues 
+                           WHERE name='nfsphys_id';
                        if (rowcount != 1) {
                            printf("Unable to retrieve unique ID\n");
                            return;
                        }
-##                     append nfsphys (nfsphys_id = id1, mach_id = id3,
-##                                     device = "???", #dir = dir, status = 0,
-##                                     allocated = 0, size = 0,
-##                                     modtime = "now", modby = 0,
-##                                     modwith = "dbck")
-##                     inquire_equel(rowcount = "rowcount")
+/*                     append nfsphys (nfsphys_id = id1, mach_id = id3,
+ *                                     device = "???", #dir = dir, status = 0,
+ *                                     allocated = 0, size = 0,
+ *                                     modtime = "now", modby = 0,
+ *                                     modwith = "dbck")
+ */
+                       EXEC SQL INSERT INTO mfsphys (mfsphys_id, mach_id,
+                           device, dir, status, allocated, size, modtime,
+                           modby, modwith) VALUES (:id1, :id3, '???', :dir,
+                           0, 0, 0, 'now', 0, 'dbck');
+                       EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
                        if (rowcount > 0)
                          printf("%d entr%s created\n", rowcount,
                                 rowcount==1?"y":"ies");
@@ -435,9 +588,11 @@ int hint;
                        n->allocated = 0;
                        n->count = 0;
                        hash_store(nfsphys, id1, n);
-##                     replace filesys (phys_id = id1)
-##                       where filesys.filsys_id = id2
-##                     inquire_equel(rowcount = "rowcount")
+/*                     replace filesys (phys_id = id1)
+ *                       where filesys.filsys_id = id2 */
+                       EXEC SQL UPDATE filesys SET phys_id = :id1
+                           WHERE filsys_id = :id2;
+                       EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
                        if (rowcount > 0)
                          printf("%d filesys entr%s fixed\n", rowcount,
                                 rowcount==1?"y":"ies");
@@ -449,7 +604,7 @@ int hint;
            }
        }
     }
-##}
+}
 
 
 check_nfsphys(id, n, hint)
@@ -465,21 +620,34 @@ int hint;
     }
 }
 
-##show_fsg_missing(id)
-##int id;
-##{
-##  int id1, found = 1;
+show_fsg_missing(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int id1, found = 1;
+    EXEC SQL END DECLARE SECTION; 
     struct filesys *f;
 
-##  retrieve (id1 = fsgroup.filsys_id) where fsgroup.group_id = id {
-      found = 0;
-      if (f = (struct filesys *) hash_lookup(filesys, id1))
-       printf("Missing fsgroup %d has member filesystem %s\n", id, f->name);
-      else
-       printf("Missing fsgroup %d has member filesystem %d\n", id, id1);
-##  }
+/*  retrieve (id1 = fsgroup.filsys_id) where fsgroup.group_id = id { */
+    EXEC SQL DECLARE csr210 CURSOR FOR
+       SELECT filsys_id FROM fsgroup
+           WHERE group_id = :id;
+    EXEC SQL OPEN csr210;
+    while(1) {
+       EXEC SQL FETCH csr210 INTO :id1;
+       if(sqlca.sqlcode != 0) break; 
+
+       found = 0;
+       if (f = (struct filesys *) hash_lookup(filesys, id1))
+           printf("Missing fsgroup %d has member filesystem %s\n", id, f->name);
+       else
+           printf("Missing fsgroup %d has member filesystem %d\n", id, id1);
+    }
+    EXEC SQL CLOSE csr210; 
     return(found);
-##}
+}
 
 show_fsg_type(f)
 struct filesys *f;
@@ -514,262 +682,426 @@ struct filesys *f;
 
 fix_fsg_type(f)
 struct filesys *f;
-##{
-##  int rowcount, id = f->filsys_id;
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount, id = f->filsys_id;
+    EXEC SQL END DECLARE SECTION; 
 
-##  replace filesys (type = "FSGROUP") where filesys.filsys_id = id
-##  inquire_equel(rowcount = "rowcount")
+/*  replace filesys (type = "FSGROUP") where filesys.filsys_id = id */
+    EXEC SQL UPDATE filesys SET type='FSGROUP' WHERE filsys_id = :id;
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount > 0)
       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not fixed\n");
     modified("filesys");
-##}
+}
 
-##show_fsg_nomember(id)
-##int id;
-##{
-##  int id1, found = 1;
+show_fsg_nomember(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int id1, found = 1;
+    EXEC SQL END DECLARE SECTION; 
     struct filesys *f;
 
-##  retrieve (id1 = fsgroup.group_id) where fsgroup.filsys_id = id {
-      found = 0;
-      if (f = (struct filesys *) hash_lookup(filesys, id1))
-       printf("FSGroup %s has missing member %d\n", f->name, id);
-      else
-       printf("FSGroup %d has missing member %d\n", id1, id);
-##  }
+/*  retrieve (id1 = fsgroup.group_id) where fsgroup.filsys_id = id { */
+    EXEC SQL DECLARE csr211 CURSOR FOR
+       SELECT group_id FROM fsgroup
+           WHERE filsys_id = :id;
+    EXEC SQL OPEN csr211;
+    while(1) {
+       EXEC SQL FETCH csr211 INTO :id1;
+       if(sqlca.sqlcode != 0) break; 
+
+       found = 0;
+       if (f = (struct filesys *) hash_lookup(filesys, id1))
+           printf("FSGroup %s has missing member %d\n", f->name, id);
+       else
+           printf("FSGroup %d has missing member %d\n", id1, id);
+    }
+    EXEC SQL CLOSE csr211; 
     return(found);
-##}
-
-##show_quota_nouser(id)
-##int id;
-##{
-##  int id1, found = 1;
-
-##  retrieve (id1 = quota.filsys_id) where quota.entity_id = id and
-##     quota.type = "USER" {
-      found = 0;
-      printf("Quota on fs %d for non-existant user %d\n", id1, id);
-##  }
+}
+
+show_quota_nouser(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int id1, found = 1;
+    EXEC SQL END DECLARE SECTION; 
+
+/*  retrieve (id1 = quota.filsys_id) where quota.entity_id = id and
+ *     quota.type = "USER" { */
+    EXEC SQL DECLARE csr212 CURSOR FOR
+       SELECT filsys_id FROM quota
+           WHERE entity_id = :id AND type='USER';
+    EXEC SQL OPEN csr212;
+    while(1) {
+       EXEC SQL FETCH csr212 INTO :id1;
+       if(sqlca.sqlcode != 0) break; 
+
+       found = 0;
+       printf("Quota on fs %d for non-existant user %d\n", id1, id);
+    }
+    EXEC SQL CLOSE csr212; 
     return(found);
-##}
-
-##show_quota_nolist(id)
-##int id;
-##{
-##  int id1, found = 1;
-
-##  retrieve (id1 = quota.filsys_id) where quota.entity_id = id and
-##     quota.type = "GROUP" {
-      found = 0;
-      printf("Quota on fs %d for non-existant list %d\n", id1, id);
-##  }
+}
+
+show_quota_nolist(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int id1, found = 1;
+    EXEC SQL END DECLARE SECTION; 
+
+/*  retrieve (id1 = quota.filsys_id) where quota.entity_id = id and
+ *     quota.type = "GROUP" { */
+    EXEC SQL DECLARE csr213 CURSOR FOR
+       SELECT filsys_id FROM quota 
+           WHERE entity_id = :id AND type='GROUP';
+    EXEC SQL OPEN csr213;
+    while(1) {
+       EXEC SQL FETCH csr213 INTO :id1;
+       if(sqlca.sqlcode != 0) break;
+       found = 0;
+       printf("Quota on fs %d for non-existant list %d\n", id1, id);
+    }
+    EXEC SQL CLOSE csr213; 
     return(found);
-##}
+}
 
-##fix_quota_nouser(id)
-##int id;
-##{
-##  int rowcount, id1;
+fix_quota_nouser(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount, id1;
+    EXEC SQL END DECLARE SECTION; 
 
     id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
-##  delete quota where quota.entity_id = id and quota.type = "USER"
-##  inquire_equel(rowcount = "rowcount")
+/*  delete quota where quota.entity_id = id and quota.type = "USER" */
+    EXEC SQL DELETE FROM quota 
+       WHERE entity_id = :id AND type = 'USER';
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount > 0)
       printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies");
     else
       printf("Not deleted\n");
     modified("quota");
-##}
+}
 
-##fix_quota_nolist(id)
-##int id;
-##{
-##  int rowcount, id1;
+fix_quota_nolist(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount, id1;
+    EXEC SQL END DECLARE SECTION; 
 
     id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
-##  delete quota where quota.entity_id = id and quota.type = "GROUP"
-##  inquire_equel(rowcount = "rowcount")
+/*  delete quota where quota.entity_id = id and quota.type = "GROUP" */
+    EXEC SQL DELETE FROM quota WHERE entity_id = :id AND type='GROUP';
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount > 0)
       printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies");
     else
       printf("Not deleted\n");
     modified("quota");
-##}
-
-##show_quota_nofs(id)
-##int id;
-##{
-##  int id1, found = 1;
-##  char type[9];
-
-##  retrieve (id1 = quota.entity_id, type = quota.#type)
-##     where quota.filsys_id = id {
-      found = 0;
-      printf("Quota for %s %d on non-existant filesys %d\n", type, id1, id);
-##  }
+}
+
+show_quota_nofs(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int id1, found = 1;
+    char type[9];
+    EXEC SQL END DECLARE SECTION; 
+
+/*  retrieve (id1 = quota.entity_id, type = quota.#type)
+ *     where quota.filsys_id = id { */
+    EXEC SQL DECLARE csr214 CURSOR FOR
+       SELECT entity_id, type FROM quota
+           WHERE filsys_id = :id;
+    EXEC SQL OPEN csr214;
+    while(1) {
+       EXEC SQL FETCH csr214 INTO :id1, :type;
+       if(sqlca.sqlcode != 0) break; 
+       
+       found = 0;
+       printf("Quota for %s %d on non-existant filesys %d\n", type, id1, id);
+    }
+    EXEC SQL CLOSE csr214;
     return(found);
-##}
+}
 
 fix_quota_nofs(id)
 {
     single_delete("quota", "filsys_id", id);
 }
 
-##show_quota_wrongpid(id)
-##int id;
-##{
-##  int id1, found = 1;
-##  char type[9];
+show_quota_wrongpid(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int id1, found = 1;
+    char type[9];
+    EXEC SQL END DECLARE SECTION; 
     struct user *u;
     struct filesys *f;
 
     f = (struct filesys *)hash_lookup(filesys, id);
-##  retrieve (id1 = quota.entity_id, type = quota.#type)
-##     where quota.filsys_id = id {
-      found = 0;
-      printf("Quota for %s %d on filesys %s has wrong phys_id %d\n",
-            type, id1, f->name, id);
-##  }
+/*  retrieve (id1 = quota.entity_id, type = quota.#type)
+ *     where quota.filsys_id = id { */
+    EXEC SQL DECLARE csr215 CURSOR FOR
+       SELECT entity_id, type FROM quota
+           WHERE filsys_id = :id;
+    EXEC SQL OPEN csr215;
+    while(1) {
+       EXEC SQL FETCH csr215 INTO :id1, :type;
+       if(sqlca.sqlcode != 0) break; 
+
+       found = 0;
+       printf("Quota for %s %d on filesys %s has wrong phys_id %d\n",
+              type, id1, f->name, id);
+    }
+    EXEC SQL CLOSE csr215; 
     return(found);
-##}
+}
 
-##fix_quota_physid(id)
-##int id;
-##{
-##  int rowcount, id1;
+fix_quota_physid(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount, id1;
+    EXEC SQL END DECLARE SECTION; 
 
     id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
-##  replace quota (phys_id = id1) where quota.filsys_id = id and
-##     quota.phys_id != id1    
-##  inquire_equel(rowcount = "rowcount")
+/*  replace quota (phys_id = id1) where quota.filsys_id = id and
+ *     quota.phys_id != id1    */
+    EXEC SQL UPDATE quota SET phys_id = :id1 
+       WHERE filsys_id = :id AND phys_id != :id1;
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount > 0)
       printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
     else
       printf("Not fixed\n");
     modified("quota");
-##}
+}
 
-##show_srv_user(id)
-##int id;
-##{
-##  char name[33];
+show_srv_user(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    char name[33];
+    EXEC SQL END DECLARE SECTION; 
     int found = 1;
 
-##  retrieve (name = s.#name) where s.acl_type = "USER" and s.acl_id = id {
+/*  retrieve (name = s.#name) where s.acl_type = "USER" and s.acl_id = id { */
+    EXEC SQL DECLARE csr216 CURSOR FOR
+       SELECT name FROM servers
+           WHERE acl_type='USER' and acl_id = :id;
+    EXEC SQL OPEN csr216;
+    while(1) {
+       EXEC SQL FETCH csr216 INTO :name;
+       if(sqlca.sqlcode != 0) break; 
+       
        strtrim(name);
        printf("Service %s has acl non-existant user %d\n", name, id);
        found = 0;
-##  }
+    }
+    EXEC SQL CLOSE csr216; 
     return(found);
-##}
+}
 
-##show_srv_list(id)
-##int id;
-##{
-##  char name[33];
+show_srv_list(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    char name[33];
+    EXEC SQL END DECLARE SECTION; 
     int found = 1;
 
-##  retrieve (name = s.#name) where s.acl_type = "LIST" and s.acl_id = id {
+/*  retrieve (name = s.#name) where s.acl_type = "LIST" and s.acl_id = id { */
+    EXEC SQL DECLARE csr217 CURSOR FOR
+       SELECT name FROM servers
+           WHERE acl_type='LIST' AND acl_id = :id;
+    EXEC SQL OPEN csr217;
+    while(1) {
+       EXEC SQL FETCH csr217 INTO :name;
+       if(sqlca.sqlcode != 0) break; 
+
        strtrim(name);
        printf("Service %s has acl non-existant list %d\n", name, id);
        found = 0;
-##  }
+    }
+    EXEC SQL CLOSE csr217; 
     return(found);
-##}
-
-##zero_srv_user(id)
-##int id;
-##{
-##  int rowcount;
+}
 
-##  replace servers (acl_id = 0) where servers.acl_id = id and
-##     servers.acl_type = "USER"
-##  inquire_equel(rowcount = "rowcount")
+zero_srv_user(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount;
+    EXEC SQL END DECLARE SECTION; 
+
+/*  replace servers (acl_id = 0) where servers.acl_id = id and
+ *     servers.acl_type = "USER" */
+    EXEC SQL UPDATE servers SET acl_id=0 WHERE acl_id = :id AND
+       acl_type='USER';
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount > 0)
       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not fixed\n");
     modified("servers");
-##}
-
-##zero_srv_list(id)
-##int id;
-##{
-##  int rowcount;
+}
 
-##  replace servers (acl_id = 0) where servers.acl_id = id and
-##     servers.acl_type = "LIST"
-##  inquire_equel(rowcount = "rowcount")
+zero_srv_list(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int rowcount;
+    EXEC SQL END DECLARE SECTION; 
+
+/*  replace servers (acl_id = 0) where servers.acl_id = id and
+ *     servers.acl_type = "LIST" */
+    EXEC SQL UPDATE servers SET acl_id=0 WHERE acl_id = :id AND
+       acl_type='LIST';
+    EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
     if (rowcount > 0)
       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not fixed\n");
     modified("servers");
-##}
+}
 
 
-##show_krb_usr(id)
-##int id;
-##{
-##  int found = 1, id1;
+show_krb_usr(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int found = 1, id1;
+    EXEC SQL END DECLARE SECTION; 
     struct string *s;
     char *ss;
 
-##  retrieve (id1 = krbmap.string_id) where krbmap.users_id = id {
+/*  retrieve (id1 = krbmap.string_id) where krbmap.users_id = id { */
+    EXEC SQL DECLARE csr218 CURSOR FOR
+       SELECT string_id FROM krbmap
+           WHERE users_id = :id ;
+    EXEC SQL OPEN csr218;
+    while(1) {
+       EXEC SQL FETCH csr218 INTO :id1;
+       if(sqlca.sqlcode != 0) break; 
+
        if (s = ((struct string *)hash_lookup(strings, id1)))
-         ss = s->name;
+           ss = s->name;
        else
-         ss = "[unknown]";
+           ss = "[unknown]";
        found = 0;
        printf("Kerberos map for non-existant user %d to principal %s\n",
               id, s);
-##  }
+    }
+    EXEC SQL CLOSE csr218; 
     return(found);
-##}
+}
 
 
-##show_krb_str(id)
-##int id;
-##{
-##  int found = 1, id1;
+show_krb_str(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int found = 1, id1;
+    EXEC SQL END DECLARE SECTION; 
     struct user *u;
     char *s;
 
-##  retrieve (id1 = krbmap.users_id) where krbmap.string_id = id {
+/*  retrieve (id1 = krbmap.users_id) where krbmap.string_id = id { */
+    EXEC SQL DECLARE csr219 CURSOR FOR
+       SELECT users_id FROM krbmap
+           WHERE string_id = :id;
+    EXEC SQL OPEN csr219;
+    while(1) {
+       EXEC SQL FETCH csr219 INTO :id1;
+       if(sqlca.sqlcode != 0) break; 
+
        if (u = ((struct user *)hash_lookup(users, id1)))
-         s = u->login;
+           s = u->login;
        else
-         s = "[???]";
+           s = "[???]";
        found = 0;
        printf("Kerberos map for user %s (%d) to non-existant string %d\n",
               s, id1, id);
-##  }
+       }
+    EXEC SQL CLOSE csr219; 
     return(found);
-##}
+}
 
 
-##show_pdm_mach(id)
-##int id;
-##{
-##  char name[33];
+show_pdm_mach(id)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id;
+EXEC SQL END DECLARE SECTION; 
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    char name[33];
+    EXEC SQL END DECLARE SECTION; 
     int found = 1;
 
-##  retrieve (name = palladium.#name) where palladium.mach_id = id {
+/*  retrieve (name = palladium.#name) where palladium.mach_id = id { */
+    EXEC SQL DECLARE csr220 CURSOR FOR
+       SELECT name FROM palladium
+           WHERE mach_id = :id;
+    EXEC SQL OPEN csr220;
+    while(1) {
+       EXEC SQL FETCH csr220 INTO :name;
+       if(sqlca.sqlcode != 0) break; 
+
        strtrim(name);
         printf("Palladium server/supervisor %s is on non-existant machine %d\n",
               name, id);
        found = 0;
-##  }
+       }
+    EXEC SQL CLOSE csr220; 
     return(found);
-##}
+}
 
 
 phase2()
-##{
-##  int id1, id2, id3, id4, id5;
-##  char type[9], name[33];
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int id1, id2, id3, id4, id5;
+    char type[9], name[33];
+    EXEC SQL END DECLARE SECTION; 
     struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5;
     struct filesys *f;
     struct list *l;
@@ -784,22 +1116,38 @@ phase2()
     dprintf("Checking mcmap...\n");
     sq1 = sq_create();
     sq2 = sq_create();
-##  retrieve (id1 = mcmap.mach_id, id2 = mcmap.clu_id) {
+/*  retrieve (id1 = mcmap.mach_id, id2 = mcmap.clu_id) { */
+    EXEC SQL DECLARE csr221 CURSOR FOR
+       SELECT mach_id, clu_id FROM mcmap;
+    EXEC SQL OPEN csr221;
+    while(1) {
+       EXEC SQL FETCH csr221 INTO :id1, :id2;
+       if(sqlca.sqlcode != 0) break; 
+
        if (!(m = (struct machine *)hash_lookup(machines, id1)))
-         sq_save_unique_data(sq1, id1);
+           sq_save_unique_data(sq1, id1);
        if (!hash_lookup(clusters, id2))
-         sq_save_unique_data(sq2, id2);
+           sq_save_unique_data(sq2, id2);
        if (m) m->clucount++;
-##  }
+       }
+    EXEC SQL CLOSE csr221; 
     generic_delete(sq1, show_mcm_mach, "mcmap", "mach_id", 1);
     generic_delete(sq2, show_mcm_clu, "mcmap", "clu_id", 1);
 
     dprintf("Checking service clusters...\n");
     sq1 = sq_create();
-##  retrieve (id1 = svc.clu_id) {
+/*  retrieve (id1 = svc.clu_id) { */
+    EXEC SQL DECLARE csr222 CURSOR FOR
+       SELECT clu_id FROM svc;
+    EXEC SQL OPEN csr222;
+    while(1) {
+       EXEC SQL FETCH csr222 INTO :id1;
+       if(sqlca.sqlcode != 0) break; 
+
        if (!hash_lookup(clusters, id1))
          sq_save_unique_data(sq1, id1);
-##  }
+    }
+    EXEC SQL CLOSE csr222; 
     generic_delete(sq1, show_svc, "svc", "clu_id", 1);
 
     dprintf("Checking lists...\n");
@@ -811,9 +1159,16 @@ phase2()
     sq3 = sq_create();
     sq4 = sq_create();
     sq5 = sq_create();
-##  range of m is imembers
-##  retrieve (id1 = m.list_id, type = m.member_type, id2 = m.member_id,
-##           id3 = m.ref_count, id4 = m.direct) {
+/*  range of m is imembers
+ *  retrieve (id1 = m.list_id, type = m.member_type, id2 = m.member_id,
+ *           id3 = m.ref_count, id4 = m.direct) {  */
+    EXEC SQL DECLARE csr223 CURSOR FOR
+       SELECT list_id, member_type, member_id, ref_count, direct FROM imembers;
+    EXEC SQL OPEN csr223;
+    while(1) {
+       EXEC SQL FETCH csr223 INTO :id1, :type, :id2, :id3, :id4;
+       if(sqlca.sqlcode != 0) break; 
+
        if ((l = (struct list *) hash_lookup(lists, id1)) == NULL)
          sq_save_unique_data(sq1, id1);
        else if (type[0] == 'U' && !hash_lookup(users, id2))
@@ -826,7 +1181,8 @@ phase2()
          sq_save_unique_data(sq5, id2);
        else
          l->members++;
-##  }
+       }
+    EXEC SQL CLOSE csr223; 
     generic_delete(sq1, show_member_list, "imembers", "list_id", 1);
     generic_fix(sq2, show_mem_user, "Delete", del_mem_user, 1);
     generic_fix(sq3, show_mem_list, "Delete", del_mem_list, 1);
@@ -836,24 +1192,40 @@ phase2()
     dprintf("Checking servers...\n");
     sq1 = sq_create();
     sq2 = sq_create();
-##  range of s is servers
-##  retrieve (name = s.#name, type = s.acl_type, id1 = s.acl_id) {
+/*  range of s is servers
+ *  retrieve (name = s.#name, type = s.acl_type, id1 = s.acl_id) { */
+    EXEC SQL DECLARE csr224 CURSOR FOR
+       SELECT name, acl_type, acl_id FROM servers;
+    EXEC SQL OPEN csr224;
+    while(1) {
+       EXEC SQL FETCH csr224 INTO :name, :type, :id1;
+       if(sqlca.sqlcode != 0) break; 
+
        strtrim(type);
        if (!strcmp(type, "USER") && !hash_lookup(users, id1)) {
            sq_save_data(sq1, id1);
        } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id1)) {
            sq_save_data(sq2, id1);
        }
-##  }
+    }
+    EXEC SQL CLOSE csr224; 
     generic_fix(sq1, show_srv_user, "Fix", zero_srv_user, 1);
     generic_fix(sq2, show_srv_list, "Fix", zero_srv_list, 1);
 
     dprintf("Checking servershosts...\n");
     sq = sq_create();
-##  retrieve (id1 = serverhosts.mach_id) {
+/*  retrieve (id1 = serverhosts.mach_id) { */
+    EXEC SQL DECLARE csr225 CURSOR FOR
+       SELECT mach_id FROM servrhosts;
+    EXEC SQL OPEN csr225;
+    while(1) {
+       EXEC SQL FETCH csr225 INTO :id1;
+       if(sqlca.sqlcode != 0) break; 
+
        if (!hash_lookup(machines, id1))
          sq_save_data(sq, id1);
-##  }
+       }
+    EXEC SQL CLOSE csr225; 
     generic_fix(sq, show_sh, "Delete", del_sh_mach, 0);
 
     dprintf("Checking nfsphys...\n");
@@ -866,12 +1238,20 @@ phase2()
     sq1 = sq_create();
     sq2 = sq_create();
     sq3 = sq_create();
-##  retrieve (id1 = fsgroup.group_id, id2 = fsgroup.filsys_id) {
+/*  retrieve (id1 = fsgroup.group_id, id2 = fsgroup.filsys_id) { */
+    EXEC SQL DECLARE csr226 CURSOR FOR
+       SELECT group_id, filsys_id FROM fsgroup;
+    EXEC SQL OPEN csr226;
+    while(1) {
+       EXEC SQL FETCH csr226 INTO :id1, :id2;
+       if(sqlca.sqlcode != 0) break; 
+
        if (!(f = (struct filesys *) hash_lookup(filesys, id1)))
          sq_save_data(sq1, id1);
        if (!hash_lookup(filesys, id2))
          sq_save_data(sq3, id2);
-##  }
+    }
+    EXEC SQL CLOSE csr226; 
     generic_delete(sq1, show_fsg_missing, "fsgroup", "group_id", 0);
     generic_delete(sq3, show_fsg_nomember, "fsgroup", "filsys_id", 1);
 
@@ -880,8 +1260,15 @@ phase2()
     sq2 = sq_create();
     sq3 = sq_create();
     sq4 = sq_create();
-##  retrieve (id1 = quota.entity_id, type = quota.#type, id2 = quota.filsys_id,
-##           id3 = quota.phys_id, id4 = quota.quota) {
+/*  retrieve (id1 = quota.entity_id, type = quota.#type, id2 = quota.filsys_id,
+ *           id3 = quota.phys_id, id4 = quota.quota) { */
+    EXEC SQL DECLARE csr227 CURSOR FOR
+       SELECT entity_id, type, filsys_id, phys_id, quota FROM quota;
+    EXEC SQL OPEN csr227;
+    while(1) {
+       EXEC SQL FETCH csr227 INTO :id1, :type, :id2, :id3, :id4;
+       if(sqlca.sqlcode != 0) break; 
+
        if (type[0] == 'U' && id1 != 0 && !hash_lookup(users, id1))
          sq_save_data(sq1, id1);
        else if (type[0] == 'G' && !hash_lookup(lists, id1))
@@ -894,7 +1281,8 @@ phase2()
          sq_save_data(sq3, id2);
        else
          n->count += id4;
-##  }
+    }
+    EXEC SQL CLOSE csr227; 
     generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1);
     generic_fix(sq2, show_quota_nofs, "Delete", fix_quota_nofs, 0);
     generic_fix(sq3, show_quota_wrongpid, "Fix", fix_quota_physid, 1);
@@ -903,8 +1291,15 @@ phase2()
     dprintf("Not checking zephyr.\n");
 
     dprintf("Checking hostaccess...\n");
-##  range of h is hostaccess
-##  retrieve (id1 = h.mach_id, type = h.acl_type, id2 = h.acl_id) {
+/*  range of h is hostaccess
+ *  retrieve (id1 = h.mach_id, type = h.acl_type, id2 = h.acl_id) { */
+    EXEC SQL DECLARE csr228 CURSOR FOR
+       SELECT mach_id, acl_type, acl_id FROM hostaccess;
+    EXEC SQL OPEN csr228;
+    while(1) {
+       EXEC SQL FETCH csr228 INTO :id1, :type, :id2;
+       if(sqlca.sqlcode != 0) break; 
+
        strtrim(type);
        if (!hash_lookup(machines, id1)) {
            printf("Hostaccess for non-existant host %d\n", id1);
@@ -917,38 +1312,63 @@ phase2()
            printf("Hostaccess for %d is non-existant list %d\n", id1, id2);
            printf("Not fixing this error\n");
        }
-##  }
+    }
+    EXEC SQL CLOSE csr228; 
 
     dprintf("Checking palladium...\n");
     sq1 = sq_create();
-##  range of p is palladium
-##  retrieve (id1 = p.mach_id) {
+/*  range of p is palladium
+ *  retrieve (id1 = p.mach_id) { */
+    EXEC SQL DECLARE csr229 CURSOR FOR
+       SELECT mach_id FROM palladium;
+    EXEC SQL OPEN csr229;
+    while(1) {
+       EXEC SQL FETCH csr229 INTO :id1;
+       if(sqlca.sqlcode != 0) break; 
+
        if (!hash_lookup(machines, id1)) {
            sq_save_unique_data(sq1, id1);
        }
-##  }
+    }
+    EXEC SQL CLOSE csr229;
     generic_delete(sq1, show_pdm_mach, "palladium", "mach_id", 1);
 
     dprintf("Checking krbmap...\n");
     sq1 = sq_create();
     sq2 = sq_create();
-##  range of k is krbmap
-##  retrieve (id1 = k.users_id, id2 = k.string_id) {
+/*  range of k is krbmap
+ *  retrieve (id1 = k.users_id, id2 = k.string_id) { */
+    EXEC SQL DECLARE csr230 CURSOR FOR
+       SELECT users_id, string_id FROM krbmap;
+    EXEC SQL OPEN csr230;
+    while(1) {
+       EXEC SQL FETCH csr230 INTO :id1, :id2;
+       if(sqlca.sqlcode != 0) break; 
+
        if (!hash_lookup(users, id1))
          sq_save_unique_data(sq1, id1);
        if (!string_check(id2))
          sq_save_unique_data(sq2, id2);
-##  }
+       }
+    EXEC SQL CLOSE csr230; 
     generic_delete(sq1, show_krb_usr, "krbmap", "users_id", 1);
     generic_delete(sq2, show_krb_str, "krbmap", "string_id", 1);
 
     dprintf("Checking capacls...\n");
-##  retrieve (id1 = capacls.list_id, name = capacls.tag) {
+/*  retrieve (id1 = capacls.list_id, name = capacls.tag) { */
+    EXEC SQL DECLARE csr231 CURSOR FOR
+       SELECT list_id, tag FROM capacls;
+    EXEC SQL OPEN csr231;
+    while(1) {
+       EXEC SQL FETCH csr231 INTO :id1, :name;
+       if(sqlca.sqlcode != 0) break; 
+
        if (!hash_lookup(lists, id1)) {
            printf("Capacl for %s is non-existant list %d\n", name, id1);
            printf("Not fixing this error\n");
        }
-##  }
+    }
+    EXEC SQL CLOSE csr231; 
 
-##}
+}
 
index 0a85f74666cf850229329c47acb1257fbadee90f..eb0923af2b5d0974ec2fb649d134f71a0052d524 100644 (file)
@@ -62,7 +62,7 @@ struct machine *m;
 
 
 phase3()
-##{
+{
     printf("Phase 3 - Finding unused objects\n");
 
     if (warn) {
@@ -76,5 +76,5 @@ phase3()
     dprintf("Checking strings...\n");
     hash_step(strings, unref_string_check, NULL);
 
-##}
+}
 
index 535a22a3be1cb2f1b8bad4a6340120539c053c10..9986e541e884ef11d8701e74bfddef7cf0bb04be 100644 (file)
@@ -8,6 +8,7 @@
 #include <mit-copyright.h>
 #include <moira.h>
 #include "dbck.h"
+EXEC SQL INCLUDE sqlca;
 
 static char phase4_qc_rcsid[] = "$Header$";
 
@@ -31,11 +32,15 @@ struct hash *boxes;
 }
 
 
-##check_box_counts(id, cnt, counts)
-##int id, cnt;
+check_box_counts(id, cnt, counts)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id, cnt;
+EXEC SQL END DECLARE SECTION; 
 struct hash *counts;
-##{
-##  int oldval, rowcount;
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int oldval, rowcount;
+    EXEC SQL END DECLARE SECTION; 
 
     oldval = (int) hash_lookup(counts, id);
     cnt--;
@@ -44,10 +49,13 @@ struct hash *counts;
               ((struct machine *) hash_lookup(machines, id))->name,
               oldval, cnt);
        if (single_fix("Update", 1)) {
-##         range of s is serverhosts
-##         replace s (value1 = cnt) where
-##             s.service = "POP" and s.mach_id = id
-##         inquire_equel(rowcount = "rowcount")
+/*         range of s is serverhosts
+ *         replace s (value1 = cnt) where
+ *             s.service = "POP" and s.mach_id = id
+ */
+           EXEC SQL UPDATE serverhosts SET value1 = :cnt
+               WHERE service='POP' AND mach_id = :id;
+           EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
            if (rowcount > 0)
              printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
            else
@@ -55,14 +63,18 @@ struct hash *counts;
            modified("serverhosts");
        }
     }
-##}
+}
 
 
-##check_nfs_counts(id, n, hint)
-##int id, hint;
+check_nfs_counts(id, n, hint)
+EXEC SQL BEGIN DECLARE SECTION; 
+int id, hint;
+EXEC SQL END DECLARE SECTION; 
 struct nfsphys *n;
-##{
-##  int val, rowcount;
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int val, rowcount;
+    EXEC SQL END DECLARE SECTION; 
 
     val = n->count;
     if (n->allocated != val) {
@@ -70,8 +82,10 @@ struct nfsphys *n;
               ((struct machine *) hash_lookup(machines, n->mach_id))->name,
               n->dir, n->allocated, val);
        if (single_fix("Update", 1)) {
-##         replace nfsphys (allocated = val) where nfsphys.nfsphys_id = id
-##         inquire_equel(rowcount = "rowcount")
+/*         replace nfsphys (allocated = val) where nfsphys.nfsphys_id = id */
+           EXEC SQL UPDATE nfsphys SET allocated = :val 
+               WHERE nfsphys_id = :id;
+           EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
            if (rowcount > 0)
              printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
            else
@@ -79,36 +93,50 @@ struct nfsphys *n;
            modified("nfsphys");
        }
     }
-##}
+}
 
 
 phase4()
-##{
+{
     struct hash *boxes, *counts;
-##  int id, cnt;
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int id, cnt;
+    EXEC SQL END DECLARE SECTION; 
 
     printf("Phase 4 - Checking counts\n");
 
     dprintf("Doing POBoxes...\n");
     boxes = create_hash(10);
     counts = create_hash(10);
-##  retrieve (id = serverhosts.mach_id, cnt = serverhosts.value1)
-##     where serverhosts.service = "POP" {
-      hash_store(boxes, id, 1);
-      hash_store(counts, id, cnt);
-##  }
+/*  retrieve (id = serverhosts.mach_id, cnt = serverhosts.value1)
+ *     where serverhosts.service = "POP" {
+ */
+    EXEC SQL DECLARE csr401 CURSOR FOR
+       SELECT mach_id, value1 FROM serverhosts
+           WHERE service='POP';
+    EXEC SQL OPEN csr401;
+    while(1) {
+       EXEC SQL FETCH csr401 INTO :id, :cnt;
+       if(sqlca.sqlcode != 0) break; 
+       
+       hash_store(boxes, id, 1);
+       hash_store(counts, id, cnt);
+    }
+    EXEC SQL CLOSE csr401; 
     hash_step(users, count_boxes, boxes);
     hash_step(boxes, check_box_counts, counts);
 
     dprintf("Doing NFSphys...\n");
     hash_step(nfsphys, check_nfs_counts, 0);
-##}
+}
 
 
 count_only_setup()
-##{
-##  int id, status, id2, id3;
-##  char name[33], last[17], first[17], buf[257];
+{
+    EXEC SQL BEGIN DECLARE SECTION; 
+    int id, status, id2, id3;
+    char name[33], last[17], first[17], buf[257];
+    EXEC SQL END DECLARE SECTION; 
     struct save_queue *sq;
     struct user *u;
     struct nfsphys *n;
@@ -116,11 +144,21 @@ count_only_setup()
 
     dprintf("Loading users...\n");
     users = create_hash(10000);
-##  range of u is users
-##  retrieve (id = u.users_id, name = u.login, last = u.#last,
-##           first = u.#first, status = u.#status, buf = u.potype,
-##           id2 = u.pop_id, id3 = u.box_id) 
-##    where u.potype = "POP" {
+/*  range of u is users
+ *  retrieve (id = u.users_id, name = u.login, last = u.#last,
+ *           first = u.#first, status = u.#status, buf = u.potype,
+ *           id2 = u.pop_id, id3 = u.box_id) 
+ *    where u.potype = "POP" { */
+    EXEC SQL DECLARE csr402 CURSOR FOR
+       SELECT users_id, login, last, first, status, 
+              potype, pop_id, box_id FROM users
+           WHERE potype='POP';
+    EXEC SQL OPEN csr402;
+    while(1) {
+       EXEC SQL FETCH csr402 INTO :id, :name, :last, :first, :status, 
+           :buf, :id2, :id3;
+       if(sqlca.sqlcode != 0) break; 
+
        u = (struct user *) malloc(sizeof(struct user));
        if (u == NULL)
          out_of_mem("storing users");
@@ -141,24 +179,40 @@ count_only_setup()
            u->pobox_id = 0;
        }
        hash_store(users, id, u);
-##  }
+       }
+    EXEC SQL CLOSE csr402; 
 
     dprintf("Loading machines...\n");
     machines = create_hash(1000);
-##  range of m is machine
-##  retrieve (id = m.mach_id, name = m.#name) {
+/*  range of m is machine
+ *  retrieve (id = m.mach_id, name = m.#name) { */
+    EXEC SQL DECLARE csr403 CURSOR FOR
+       SELECT mach_id, name FROM machine;
+    EXEC SQL OPEN csr403;
+    while(1) {
+       EXEC SQL FETCH csr403 INTO :id, :name;
+       if(sqlca.sqlcode != 0) break; 
+
        m = (struct machine *) malloc(sizeof(struct machine));
        if (m == NULL)
          out_of_mem("storing machines");
        strcpy(m->name, strtrim(name));
        m->mach_id = id;
        hash_store(machines, id, m);
-##  }
+    }
+    EXEC SQL CLOSE csr403; 
 
     dprintf("Loading nfsphys...\n");
     nfsphys = create_hash(500);
-##  retrieve (id = nfsphys.nfsphys_id, name = nfsphys.dir,
-##           id2 = nfsphys.mach_id, id3 = nfsphys.allocated) {
+/*  retrieve (id = nfsphys.nfsphys_id, name = nfsphys.dir,
+ *           id2 = nfsphys.mach_id, id3 = nfsphys.allocated) { */
+    EXEC SQL DECLARE csr404 CURSOR FOR
+       SELECT nfsphys_id, dir, mach_id, allocated FROM nfsphys;
+    EXEC SQL OPEN csr404;
+    while(1) {
+       EXEC SQL FETCH csr404 INTO :id, :name, :id2, :id3;
+       if(sqlca.sqlcode != 0) break; 
+
        n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
        if (n == NULL)
          out_of_mem("storing nfsphys");
@@ -168,12 +222,21 @@ count_only_setup()
        n->allocated = id3;
        n->count = 0;
        hash_store(nfsphys, id, n);
-##  }
+       }
+    EXEC SQL CLOSE csr404; 
 
     dprintf("Counting quotas...\n");
-##  retrieve (id = quota.phys_id, id2 = quota.quota) {
+/*  retrieve (id = quota.phys_id, id2 = quota.quota) { */
+    EXEC SQL DECLARE csr405 CURSOR FOR
+       SELECT phys_id, quota FROM quota;
+    EXEC SQL OPEN csr405;
+    while(1) {
+       EXEC SQL FETCH csr405 INTO :id, :id2;
+       if(sqlca.sqlcode != 0) break; 
+       
         if (n = (struct nfsphys  *) hash_lookup(nfsphys, id)) {
            n->count += id2;
        }
-##  }
-##}
+    }
+    EXEC SQL CLOSE csr405; 
+}
This page took 0.138768 seconds and 5 git commands to generate.