]> andersk Git - moira.git/blobdiff - dbck/phase1.dc
Diane Delgado's changes for a fixed table-locking order
[moira.git] / dbck / phase1.dc
index 91984c7a4c649b99c22009a7551fd9c05190b2ba..a937cebe9b474d319b34a15279dc4badfefe6db7 100644 (file)
@@ -49,8 +49,6 @@ struct save_queue *sq;
                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);
@@ -204,10 +202,14 @@ phase1()
 
     EXEC SQL DECLARE csr101 CURSOR FOR
       SELECT string_id, string FROM strings ORDER BY string_id;
+    if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
     EXEC SQL OPEN csr101;
     while(1) {
        EXEC SQL FETCH csr101 INTO :id, :buf;
-       if(sqlca.sqlcode != 0) break;
+       if (sqlca.sqlcode != 0) {
+         ingerr(&sqlca.sqlcode);
+         break;
+       }
 
        s = (struct string *) malloc(sizeof(struct string));
        if (s == NULL)
@@ -231,11 +233,15 @@ phase1()
     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 ORDER BY users_id;
+    if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
     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;
+       if (sqlca.sqlcode != 0) {
+         ingerr(&sqlca.sqlcode);
+         break;
+       }
 
        u = (struct user *) malloc(sizeof(struct user));
        if (u == NULL)
@@ -281,10 +287,14 @@ phase1()
        EXEC SQL DECLARE csr103 CURSOR FOR 
            SELECT u1.users_id FROM users u1, users u2
            WHERE u1.login = u2.login and u1.tid != u2.tid;
+       if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
        EXEC SQL OPEN csr103;
        while(1) {
            EXEC SQL FETCH csr103 INTO :id;
-           if(sqlca.sqlcode != 0) break;
+           if (sqlca.sqlcode != 0) {
+               ingerr(&sqlca.sqlcode);
+               break;
+           }
            sq_save_data(sq, hash_lookup(users, id));
        }
        EXEC SQL CLOSE csr103; 
@@ -296,24 +306,36 @@ phase1()
     sq = sq_create();
 
     EXEC SQL DECLARE csr104 CURSOR FOR
-       SELECT mach_id, name, modby FROM machine ORDER BY mach_id;
+       SELECT mach_id, name, snet_id, owner_type, owner_id,
+               acomment, ocomment, creator, modby
+       FROM machine ORDER BY mach_id;
+    if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
     EXEC SQL OPEN csr104;
     while(1) {
-       EXEC SQL FETCH csr104 INTO :id, :name, :sid;
-       if(sqlca.sqlcode != 0) break; 
+       EXEC SQL FETCH csr104 INTO :id, :name, :id2, :buf, :id3, :sid2,
+               :sid3, :sid4, :sid;
+       if (sqlca.sqlcode != 0) {
+         ingerr(&sqlca.sqlcode);
+         break;
+       } 
 
        m = (struct machine *) malloc(sizeof(struct machine));
        if (m == NULL)
          out_of_mem("storing machines");
        strcpy(m->name, strtrim(name));
+       m->owner_type = buf[0];
+       m->owner_id = id3;
+       m->snet_id = id2;
        m->mach_id = id;
        m->clucount = 0;
        if (hash_store(machines, id, m)) {
            sq_save_data(sq, hash_lookup(machines, id));
            sq_save_data(sq, m);
        }
-       if (sid < 0)
-         string_check(-sid);
+       if (sid2) string_check(sid2);
+       if (sid3) string_check(sid3);
+       if (sid4 < 0) string_check(-sid4);
+       if (sid < 0) string_check(-sid);
     }
     EXEC SQL CLOSE csr104; 
     generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0);
@@ -324,10 +346,14 @@ phase1()
        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;
+       if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
        EXEC SQL OPEN csr105;
        while(1) {
            EXEC SQL FETCH csr105 INTO :id;
-           if(sqlca.sqlcode != 0) break; 
+           if (sqlca.sqlcode != 0) {
+               ingerr(&sqlca.sqlcode);
+               break;
+           } 
 
            sq_save_data(sq, hash_lookup(machines, id));
        }
@@ -335,16 +361,39 @@ phase1()
        generic_fix(sq, show_mach_name, "Change name", cant_fix, 0);
     }  
 
+    dprintf("Loading subnets...\n");
+    subnets = create_hash(254);
+
+    EXEC SQL DECLARE csr115 CURSOR FOR
+      SELECT snet_id, name from subnet;
+    if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
+    EXEC SQL OPEN csr115;
+    while(1) {
+       EXEC SQL FETCH csr115 INTO :id, :name;
+       if (sqlca.sqlcode != 0) {
+         ingerr(&sqlca.sqlcode);
+         break;
+       } 
+       if (hash_store(subnets, id, name)) {
+           printf("Duplicate subnet ID: %d (%s)\n", id, name);
+       }
+    }
+    EXEC SQL CLOSE csr115;
+
     dprintf("Loading clusters...\n");
     sq = sq_create();
     clusters = create_hash(100);
 
     EXEC SQL DECLARE csr106 CURSOR FOR
        SELECT clu_id, name, modby FROM cluster;
+    if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
     EXEC SQL OPEN csr106;
     while(1) {
        EXEC SQL FETCH csr106 INTO :id, :name, :sid;
-       if(sqlca.sqlcode != 0) break; 
+       if (sqlca.sqlcode != 0) {
+         ingerr(&sqlca.sqlcode);
+         break;
+       } 
 
        c = (struct cluster *) malloc(sizeof(struct cluster));
        if (c == NULL)
@@ -365,12 +414,16 @@ phase1()
        sq = sq_create();
 
        EXEC SQL DECLARE csr107 CURSOR FOR
-           SELECT clu_id FROM cluster c1, cluster c2
+           SELECT c1.clu_id FROM cluster c1, cluster c2
                WHERE c1.name=c2.name AND c1.tid != c2.tid;
+       if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
        EXEC SQL OPEN csr107;
        while(1) {
            EXEC SQL FETCH csr107 INTO :id;
-           if(sqlca.sqlcode != 0) break; 
+           if (sqlca.sqlcode != 0) {
+               ingerr(&sqlca.sqlcode);
+               break;
+           } 
 
            sq_save_data(sq, hash_lookup(clusters, id));
        }
@@ -385,10 +438,14 @@ phase1()
     EXEC SQL DECLARE csr108 CURSOR FOR
        SELECT list_id, name, acl_id, acl_type, modby  FROM list 
        ORDER BY list_id;
+    if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
     EXEC SQL OPEN csr108;
     while(1) {
        EXEC SQL FETCH csr108 INTO :id, :name, :aid, :buf, :sid;
-       if (sqlca.sqlcode != 0) break;
+       if (sqlca.sqlcode != 0) {
+         ingerr(&sqlca.sqlcode);
+         break;
+       }
        l = (struct list *) malloc(sizeof(struct list));
        if (l == NULL)
          out_of_mem("storing lists");
@@ -411,12 +468,16 @@ phase1()
        sq = sq_create();
 
        EXEC SQL DECLARE csr109 CURSOR FOR
-           SELECT list_id FROM list l1, list l2
+           SELECT l1.list_id FROM list l1, list l2
                WHERE l1.name=l2.name AND l1.tid != l2.tid;
+       if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
        EXEC SQL OPEN csr109;
        while(1) {
            EXEC SQL FETCH csr109 INTO :id;
-           if(sqlca.sqlcode != 0) break; 
+           if (sqlca.sqlcode != 0) {
+               ingerr(&sqlca.sqlcode);
+               break;
+           } 
            
            sq_save_data(sq, hash_lookup(lists, id));
        }
@@ -431,11 +492,15 @@ phase1()
     EXEC SQL DECLARE csr110 CURSOR FOR
        SELECT filsys_id, label, owner, owners, phys_id, mach_id,
                type, name, modby FROM filesys ORDER BY filsys_id;
+    if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
     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;
+       if (sqlca.sqlcode != 0) {
+         ingerr(&sqlca.sqlcode);
+         break;
+       }
 
        f = (struct filesys *) malloc(sizeof(struct filesys));
        if (f == NULL)
@@ -465,10 +530,14 @@ phase1()
 
     EXEC SQL DECLARE csr111 CURSOR FOR
        SELECT nfsphys_id, dir, mach_id, allocated, modby FROM nfsphys;
+    if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
     EXEC SQL OPEN csr111;
     while(1) {
        EXEC SQL FETCH csr111 INTO :id, :name, :id2, :id3, :sid;
-       if(sqlca.sqlcode != 0) break; 
+       if (sqlca.sqlcode != 0) {
+           ingerr(&sqlca.sqlcode);
+           break;
+       } 
 
        n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
        if (n == NULL)
@@ -491,13 +560,18 @@ phase1()
 
     if (!fast) {
 
+       dprintf("Checking for duplicate strings...\n");
        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;
+       if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
        EXEC SQL OPEN csr112;
        while(1) {
            EXEC SQL FETCH csr112 INTO :id, :buf;
-           if(sqlca.sqlcode != 0) break; 
+           if (sqlca.sqlcode != 0) {
+               ingerr(&sqlca.sqlcode);
+               break;
+           } 
 
            printf("String %s(%d) is a duplicate!\n", strtrim(buf), id);
            printf("Not fixing this error\n");
@@ -511,10 +585,14 @@ phase1()
        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;
+       if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
        EXEC SQL OPEN csr113;
        while(1) {
            EXEC SQL FETCH csr113 INTO :id;
-           if(sqlca.sqlcode != 0) break; 
+           if (sqlca.sqlcode != 0) {
+               ingerr(&sqlca.sqlcode);
+               break;
+           } 
 
            printf("User %d is in the krbmap more than once!\n", id);
            printf("Not fixing this error\n");
@@ -524,10 +602,14 @@ phase1()
        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;
+       if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
        EXEC SQL OPEN csr114;
        while(1) {
            EXEC SQL FETCH csr114 INTO :id;
-           if(sqlca.sqlcode != 0) break; 
+           if (sqlca.sqlcode != 0) {
+               ingerr(&sqlca.sqlcode);
+               break;
+           } 
 
            printf("Principal %d is in the krbmap more than once!\n", id);
            printf("Not fixing this error\n");
This page took 0.046578 seconds and 4 git commands to generate.