]> andersk Git - moira.git/blobdiff - server/qsupport.dc
stuff for hosttable in moira
[moira.git] / server / qsupport.dc
index 5fe33e1c5310f825bdf6d1d7e3cc81d6f70b0ef4..21bdf88e3c111262584b8fc80f4c5c8bcdb8860b 100644 (file)
@@ -29,8 +29,6 @@ extern int ingres_errno, mr_errcode;
 
 EXEC SQL BEGIN DECLARE SECTION;
 extern char stmt_buf[];
-int idummy;
-extern char cdummy[];           
 EXEC SQL END DECLARE SECTION;
 
 /* Specialized Access Routines */
@@ -398,7 +396,7 @@ int setup_dusr(q, argv)
     char **argv;
 {
     EXEC SQL BEGIN DECLARE SECTION;
-    int flag, id;
+    int flag, id, cnt;
     EXEC SQL END DECLARE SECTION;
 
     id = *(int *)argv[0];
@@ -409,26 +407,27 @@ int setup_dusr(q, argv)
     if (flag != 0 && flag != 4)
       return(MR_IN_USE);
 
-    EXEC SQL REPEATED DELETE FROM quota WHERE entity_id = :id AND type = 'USER';
+    EXEC SQL REPEATED DELETE FROM quota WHERE entity_id = :id AND type='USER';
     EXEC SQL REPEATED DELETE FROM krbmap WHERE users_id = :id;
-    EXEC SQL REPEATED SELECT member_id INTO :idummy FROM imembers
+    EXEC SQL REPEATED SELECT COUNT(member_id) INTO :cnt FROM imembers
       WHERE member_id = :id AND member_type = 'USER';
-    if (sqlca.sqlerrd[2] > 0)
+    if (cnt > 0)
        return(MR_IN_USE);
-    EXEC SQL REPEATED SELECT label INTO :cdummy FROM filesys WHERE owner = :id;
-    if (sqlca.sqlerrd[2]> 0)
+    EXEC SQL REPEATED SELECT COUNT(label) INTO :cnt FROM filesys 
+       WHERE owner = :id;
+    if (cnt > 0)
        return(MR_IN_USE);
-    EXEC SQL REPEATED SELECT name INTO :cdummy FROM list
+    EXEC SQL REPEATED SELECT COUNT(name) INTO :cnt FROM list
       WHERE acl_id = :id AND acl_type = 'USER';
-    if (sqlca.sqlerrd[2] > 0)
+    if (cnt > 0)
        return(MR_IN_USE);
-    EXEC SQL REPEATED SELECT name INTO :cdummy FROM servers
+    EXEC SQL REPEATED SELECT COUNT(name) INTO :cnt FROM servers
       WHERE acl_id = :id AND acl_type = 'USER';
-    if (sqlca.sqlerrd[2] > 0)
+    if (cnt > 0)
        return(MR_IN_USE);
-    EXEC SQL REPEATED SELECT acl_id INTO :idummy FROM hostaccess
+    EXEC SQL REPEATED SELECT COUNT(acl_id) INTO :cnt FROM hostaccess
       WHERE acl_id = :id AND acl_type = 'USER';
-    if (sqlca.sqlerrd[2] > 0)
+    if (cnt > 0)
        return(MR_IN_USE);
     if (ingres_errno)
        return(mr_errcode);
@@ -494,37 +493,37 @@ int setup_dmac(q, argv)
     char **argv;
 {
     EXEC SQL BEGIN DECLARE SECTION;
-    int flag, id;
+    int flag, id, cnt;
     EXEC SQL END DECLARE SECTION;
 
     id = *(int *)argv[0];
-    EXEC SQL REPEATED SELECT login INTO :cdummy FROM users
+    EXEC SQL REPEATED SELECT COUNT(login) INTO :cnt FROM users
       WHERE potype='POP' AND pop_id = :id;
-    if (sqlca.sqlerrd[2] > 0)
+    if (cnt > 0)
        return(MR_IN_USE);
-    EXEC SQL REPEATED SELECT mach_id INTO :idummy FROM serverhosts
+    EXEC SQL REPEATED SELECT COUNT(mach_id) INTO :cnt FROM serverhosts
       WHERE mach_id = :id;
-    if (sqlca.sqlerrd[2] > 0)
+    if (cnt > 0)
        return(MR_IN_USE);
-    EXEC SQL REPEATED SELECT mach_id INTO :idummy FROM nfsphys
+    EXEC SQL REPEATED SELECT COUNT(mach_id) INTO :cnt FROM nfsphys
       WHERE mach_id = :id;
-    if (sqlca.sqlerrd[2] > 0)
+    if (cnt > 0)
        return(MR_IN_USE);
-    EXEC SQL REPEATED SELECT mach_id INTO :idummy FROM hostaccess
+    EXEC SQL REPEATED SELECT COUNT(mach_id) INTO :cnt FROM hostaccess
       WHERE mach_id = :id;
-    if (sqlca.sqlerrd[2] > 0)
+    if (cnt > 0)
        return(MR_IN_USE);
-    EXEC SQL REPEATED SELECT mach_id INTO :idummy FROM printcap
+    EXEC SQL REPEATED SELECT COUNT(mach_id) INTO :cnt FROM printcap
       WHERE mach_id = :id;
-    if (sqlca.sqlerrd[2] > 0)
+    if (cnt > 0)
        return(MR_IN_USE);
-    EXEC SQL REPEATED SELECT quotaserver INTO :idummy FROM printcap
+    EXEC SQL REPEATED SELECT COUNT(quotaserver) INTO :cnt FROM printcap
       WHERE quotaserver = :id;
-    if (sqlca.sqlerrd[2] > 0)
+    if (cnt > 0)
        return(MR_IN_USE);
-    EXEC SQL REPEATED SELECT mach_id INTO :idummy FROM palladium
+    EXEC SQL REPEATED SELECT COUNT(mach_id) INTO :cnt FROM palladium
       WHERE mach_id = :id;
-    if (sqlca.sqlerrd[2] > 0)
+    if (cnt > 0)
        return(MR_IN_USE);
 
     EXEC SQL REPEATED DELETE FROM mcmap WHERE mach_id = :id;
@@ -542,17 +541,17 @@ int setup_dclu(q, argv)
     char **argv;
 {
     EXEC SQL BEGIN DECLARE SECTION;
-    int id;
+    int id, cnt;
     EXEC SQL END DECLARE SECTION;
 
     id = *(int *)argv[0];
-    EXEC SQL REPEATED SELECT mach_id INTO :idummy FROM mcmap
+    EXEC SQL REPEATED SELECT COUNT(mach_id) INTO :cnt FROM mcmap
       WHERE clu_id = :id;
-    if (sqlca.sqlerrd[2] > 0)
+    if (cnt > 0)
        return(MR_IN_USE);
-    EXEC SQL REPEATED SELECT clu_id INTO :idummy FROM svc
+    EXEC SQL REPEATED SELECT COUNT(clu_id) INTO :cnt FROM svc
       WHERE clu_id = :id;
-    if (sqlca.sqlerrd[2] > 0)
+    if (cnt > 0)
        return(MR_IN_USE);
     if (ingres_errno)
        return(mr_errcode);
@@ -571,7 +570,7 @@ int setup_dclu(q, argv)
 static int badlistchars[] = {
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P - ^_ */
-    0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* SPACE - / */
+    1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* SPACE - / */
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, /* 0 - ? */
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* @ - O */
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, /* P - _ */
@@ -700,17 +699,26 @@ int setup_dsin(q, argv)
     struct query *q;
     char **argv;
 {
+    EXEC SQL BEGIN DECLARE SECTION;     
     int ec;
+    char *svrname;
+    EXEC SQL END DECLARE SECTION;
 
     sprintf(stmt_buf,"SELECT service FROM serverhosts WHERE service = UPPERCASE('%s')",argv[0]);
     if(ec=mr_select_any(stmt_buf)) {
-       if(ec==MR_EXISTS) return(MR_IN_USE); else return(ec);
+       if(ec==MR_EXISTS) 
+           return(MR_IN_USE); 
+       else 
+           return(ec);
     }
 
-    sprintf(stmt_buf,"SELECT inprogress FROM servers WHERE name = UPPERCASE('%s')",argv[0]);
-    if(ec=mr_select_any(stmt_buf)) {
-       if(ec==MR_EXISTS) return(MR_IN_USE); else return(ec);
-    }
+    svrname=argv[0];
+    EXEC SQL SELECT inprogress INTO :ec FROM servers 
+      WHERE name=UPPERCASE(:svrname);
+    if(ingres_errno) 
+       return(mr_errcode);
+    if(ec) 
+       return(MR_IN_USE); 
 
     return(MR_SUCCESS);
 }
@@ -726,15 +734,19 @@ int setup_dshi(q, argv)
 {
     EXEC SQL BEGIN DECLARE SECTION;
     int id, ec;
+    char *svrname;
     EXEC SQL END DECLARE SECTION;
 
+    svrname=argv[0];
     id = *(int *)argv[1];
 
-    sprintf(stmt_buf,"SELECT inprogress FROM serverhosts \
-WHERE service = UPPERCASE('%s') AND mach_id = %d",argv[0],id);
-    if(ec=mr_select_any(stmt_buf)) {
-       if(ec==MR_EXISTS) return(MR_IN_USE); else return(ec);
-    }
+    EXEC SQL SELECT inprogress INTO :ec FROM serverhosts 
+      WHERE service=UPPERCASE(:svrname) AND mach_id = :id;
+    if(ingres_errno) 
+       return(mr_errcode);
+    if(ec) 
+       return(MR_IN_USE); 
+
 
     return(MR_SUCCESS);
 }
@@ -789,17 +801,17 @@ setup_afil(q, argv, cl)
     var_phys_id = 0;
 
     sprintf(ftype, "fs_access_%s", type);
-    EXEC SQL SELECT trans INTO :cdummy FROM alias
-      WHERE name = :ftype AND type = 'TYPE' and trans = :access;   /** Use mr_select_any() */
+    EXEC SQL SELECT COUNT(trans) INTO :ok FROM alias
+       WHERE name = :ftype AND type = 'TYPE' and trans = :access;   
     if (ingres_errno) return(mr_errcode);
-    if (sqlca.sqlerrd[2] == 0) return(MR_FILESYS_ACCESS);
-
-    if (!strcmp(type, "NFS"))
-       return (check_nfs(mach_id, name, access));
+    if (ok == 0) return(MR_FILESYS_ACCESS);
 
     if((mr_errcode=prefetch_value(q,argv,cl))!=MR_SUCCESS)
       return(mr_errcode);
 
+    if (!strcmp(type, "NFS"))
+       return (check_nfs(mach_id, name, access));
+
     return(MR_SUCCESS);
 }
 
@@ -817,9 +829,10 @@ setup_ufil(q, argv, cl)
     int mach_id, status;
     char *type, *name;
     EXEC SQL BEGIN DECLARE SECTION;
-    int fid, total, who;
+    int fid, total, who, ok;
     char *entity, ftype[32], *access;
     int var_phys_id = 0;
+    short int total_null;
     EXEC SQL END DECLARE SECTION;
 
     type = argv[2];
@@ -831,10 +844,15 @@ setup_ufil(q, argv, cl)
     entity = cl->entity;
 
     sprintf(ftype, "fs_access_%s", type);
-    EXEC SQL SELECT trans INTO :cdummy FROM alias
+    EXEC SQL SELECT COUNT(trans) INTO :ok FROM alias
       WHERE name = :ftype AND type='TYPE' AND trans = :access;
     if (ingres_errno) return(mr_errcode);
-    if (sqlca.sqlerrd[2] == 0) return(MR_FILESYS_ACCESS);
+    if (ok == 0) return(MR_FILESYS_ACCESS);
+
+    EXEC SQL SELECT type INTO :ftype FROM filesys
+      WHERE filsys_id = :fid;
+    strtrim(ftype);
+    if (ingres_errno) return(mr_errcode);
 
     if (!strcmp(type, "NFS")) {
        status = check_nfs(mach_id, name, access);
@@ -842,14 +860,14 @@ setup_ufil(q, argv, cl)
          WHERE filsys_id = :fid;
        if (ingres_errno) return(mr_errcode);
        return(status);
-    } else if (!strcmp(type, "AFS")) {
+    } else if (!strcmp(type, "AFS") && strcmp(ftype, "AFS")) {
        total = 0;
        EXEC SQL REPEATED DELETE FROM quota
          WHERE type = 'ANY' AND filsys_id = :fid;
-       EXEC SQL SELECT SUM (quota) INTO :total FROM quota
+       EXEC SQL SELECT SUM (quota) INTO :total:total_null FROM quota
          WHERE filsys_id = :fid AND phys_id != 0;
        if (ingres_errno) return(mr_errcode);
-       if (total != 0) {
+       if (!total_null && (total != 0)) {
 /*
  *             append quota (quota = total, filsys_id = fid,
  *                          phys_id = 0, entity_id = 0, type = "ANY",
@@ -895,7 +913,11 @@ check_nfs(mach_id, name, access)
       SELECT nfsphys_id, TRIM (dir) FROM nfsphys
        WHERE mach_id = :mach_id
        ORDER BY 2 DESC;
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr101;
+    if (ingres_errno)
+       return(mr_errcode);
     while(1) {
        EXEC SQL FETCH csr101 INTO :var_phys_id, :dir;
        if(sqlca.sqlcode != 0) break;
@@ -927,18 +949,25 @@ setup_dfil(q, argv, cl)
     client *cl;
 {
     EXEC SQL BEGIN DECLARE SECTION;
-    int id, total;
+    int id, total, phys_id;
+    short int none;
     EXEC SQL END DECLARE SECTION;
 
     id = *(int *)argv[0];
-    EXEC SQL REPEATED SELECT SUM (quota) INTO :total FROM quota
+    EXEC SQL REPEATED SELECT SUM (quota) INTO :total:none FROM quota
+      WHERE filsys_id = :id;
+
+    if(none) total=0;
+
+    /** What if there are multiple phys_id's per f/s? (bad data) **/
+    EXEC SQL REPEATED SELECT phys_id INTO :phys_id FROM filesys
       WHERE filsys_id = :id;
     EXEC SQL REPEATED UPDATE nfsphys SET allocated = allocated - :total
-      WHERE nfsphys_id = filesys.phys_id AND filesys.filsys_id = :id;
-    /** Is SQL smart enough to do the PRODUCT above? */
-    /** Or should we code it using another SELECT?  */
+      WHERE nfsphys_id = :phys_id;
 
-    EXEC SQL REPEATED DELETE FROM quota WHERE filsys_id = :id;
+    if(!none) {
+       EXEC SQL REPEATED DELETE FROM quota WHERE filsys_id = :id;
+    }
     EXEC SQL REPEATED DELETE FROM fsgroup WHERE filsys_id = :id;
     EXEC SQL REPEATED DELETE FROM fsgroup WHERE group_id = :id;
     if (ingres_errno) return(mr_errcode);
@@ -956,16 +985,16 @@ setup_dnfp(q, argv, cl)
     client *cl;
 {
     EXEC SQL BEGIN DECLARE SECTION;
-    int id;
+    int id, cnt;
     char *dir;
     EXEC SQL END DECLARE SECTION;
 
     id = *(int *)argv[0];
     dir = argv[1];
-    EXEC SQL REPEATED SELECT label INTO :cdummy FROM filesys fs, nfsphys np
+    EXEC SQL REPEATED SELECT fs.tid INTO :cnt FROM filesys fs, nfsphys np
       WHERE fs.mach_id = :id AND fs.phys_id = np.nfsphys_id
        AND np.mach_id = :id AND np.dir = :dir;
-    if (sqlca.sqlerrd[2] > 0)
+    if (cnt > 0)
       return(MR_IN_USE);
     if (ingres_errno)
       return(mr_errcode);
@@ -1013,15 +1042,18 @@ setup_dqot(q, argv, cl)
 /* setup_sshi: don't exclusive lock the machine table during
  * set_server_host_internal.
  */
-
+/** Not allowed under (INGRES) SQL **/
 setup_sshi(q, argv, cl)
     struct query  *q;
     char **argv;
     client *cl;
 {
+#if 0
 #ifsql INGRES
     EXEC SQL set lockmode session where readlock = system;
 #endsql
+#endif
+    return(MR_SUCCESS);
 }
 
 
@@ -1042,12 +1074,7 @@ client *cl;
     name = argv[1];
     if (name_to_id(name, "STRING", &id) != MR_SUCCESS) {
        if (q->type != APPEND) return(MR_STRING);
-       EXEC SQL SELECT value INTO :id FROM numvalues
-         WHERE name = 'strings_id';
-       id++;
-       EXEC SQL UPDATE numvalues SET value = :id
-         WHERE name = 'strings_id';
-       EXEC SQL INSERT INTO strings (string_id, string) VALUES (:id, :name);
+       id=add_string(name);
        cache_entry(name, "STRING", id);
     }
     if (ingres_errno) return(mr_errcode);
@@ -1397,12 +1424,16 @@ followup_guax(q, sq, v, action, actarg, cl)
     EXEC SQL BEGIN DECLARE SECTION; 
     int timestamp, who;
     char *login;
+    varchar struct { short data_size; char data_buf[257];} rsig;
     EXEC SQL END DECLARE SECTION; 
 #endif /* GDSS */
     int id, status;
 
     i = q->vcnt - 2;
     while (sq_get_data(sq, &argv)) {
+#ifdef DEBUG
+       com_err(whoami, 0, "argv[SIGNATURE] = \"%s\"", argv[U_SIGNATURE]);
+#endif /* DEBUG */
        id = atoi(argv[i]);
        if (id > 0)
          status = id_to_name(id, "USER", &argv[i]);
@@ -1413,9 +1444,9 @@ followup_guax(q, sq, v, action, actarg, cl)
 #ifdef GDSS
        if (q->vcnt == U_END && strlen(argv[U_SIGNATURE])) {
            login = argv[U_NAME];
-           EXEC SQL REPEATED SELECT sigdate, sigwho 
-             INTO :timestamp, :who FROM users
-             WHERE login = LEFT(:login,SIZE(login));
+           EXEC SQL REPEATED SELECT signature, sigdate, sigwho 
+             INTO :rsig, :timestamp, :who FROM users
+             WHERE login = :login;
            /** What about (INGRES) error handling? **/
            kname = malloc(1);
             status = id_to_name(who, "STRING", &kname);
@@ -1423,9 +1454,16 @@ followup_guax(q, sq, v, action, actarg, cl)
            si.SigInfoVersion = 0; /* XXXXX this isn't used */
            kname_parse(si.pname, si.pinst, si.prealm, kname);
             free(kname);
-            si.rawsig = (unsigned char *)argv[U_SIGNATURE];
+           rsig.data_buf[rsig.data_size] = 0;
+            si.rawsig = (unsigned char *)strsave(rsig.data_buf);
+           if (log_flags & LOG_GDSS)
+             com_err(whoami, 0, "rawsig length = %d, sig=\"%s\"", strlen(si.rawsig), si.rawsig);
            GDSS_Recompose(&si, sigbuf);
+           free(si.rawsig);
+           free(argv[U_SIGNATURE]);
            argv[U_SIGNATURE] = strsave(sigbuf);
+           if (log_flags & LOG_GDSS)
+             com_err(whoami, 0, "generated signature length %d", strlen(sigbuf));
        }
 #endif /* GDSS */
        (*action)(q->vcnt, argv, actarg);
@@ -1478,6 +1516,13 @@ followup_ausr(q, argv, cl)
 
 #ifdef GDSS
       if (q->vcnt == U_END && *argv[U_SIGNATURE]) {
+       /* unquote ' chars in signature */
+       for (dst = src = argv[U_SIGNATURE]; *src; ) {
+           if (*src == '\'')
+             src++;
+           *dst++ = *src++;
+       }
+       *dst = 0;
         sprintf(databuf, "%s:%s", argv[U_NAME], argv[U_MITID]);
         /* skip bytes for timestamp & kname */
         si.rawsig = (unsigned char *) rawsig;
@@ -1490,18 +1535,15 @@ followup_ausr(q, argv, cl)
             name = kname_unparse(si.pname, si.pinst, si.prealm);
             status = name_to_id(name, "STRING", &sigwho);
             if (status == MR_NO_MATCH) {
-                EXEC SQL REPEATED SELECT value INTO :sigwho FROM numvalues
-                 WHERE name='strings_id';
-                sigwho++;
-                EXEC SQL REPEATED UPDATE numvalues SET value = :sigwho
-                 WHERE name='strings_id';
-                INSERT INTO strings (string_id, string) 
-                 VALUES (:sigwho, :name);
+             sigwho=add_string(name);
             } else if (status)
-              return(gdss2et(status));
+              return(status);
             timestamp = si.timestamp;
-        } else
-          return(gdss2et(status));
+        } else {
+           if (log_flags & LOG_GDSS)
+             hex_dump(argv[U_SIGNATURE]);
+           return(gdss2et(status));
+       }
       } else {
         rawsig[0] = 0;
         sigwho = 0;
@@ -1551,7 +1593,7 @@ followup_uuac(q, argv, cl)
 {
     EXEC SQL BEGIN DECLARE SECTION; 
     int who, status, id;
-    char *entity, *name;
+    char *entity, *name, *src, *dst;
     EXEC SQL END DECLARE SECTION; 
 #ifdef GDSS
     char databuf[32], *kname_unparse();
@@ -1569,13 +1611,26 @@ followup_uuac(q, argv, cl)
     
 #ifdef GDSS
     if (q->vcnt == U_MODTIME && *argv[U_SIGNATURE + 1]) {
+       /* unquote ' chars in signature */
+       for (dst = src = argv[U_SIGNATURE+1]; *src; ) {
+           if (*src == '\'')
+             src++;
+           *dst++ = *src++;
+       }
+       *dst = 0;
         login = malloc(1);
         status = id_to_name(id, "USER", &login);
         sprintf(databuf, "%s:%s", login, argv[U_MITID+1]);
         free(login);
         /* skip bytes for timestamp & kname */
         si.rawsig = (unsigned char *) rawsig;
+#ifdef DEBUG
+       com_err(whoami, 0, "verifying sig");
+#endif /* DEBUG */
         status = GDSS_Verify(databuf, strlen(databuf), argv[U_SIGNATURE+1], &si);
+#ifdef DEBUG
+       com_err(whoami, 0, "verified");
+#endif /* DEBUG */
        if (strlen(rawsig) > mr_sig_length) {
            com_err(whoami, 0, "GDSS signature would be truncated.");  /** untested **/
            return(MR_INTERNAL);
@@ -1584,18 +1639,15 @@ followup_uuac(q, argv, cl)
             name = kname_unparse(si.pname, si.pinst, si.prealm);
             status = name_to_id(name, "STRING", &sigwho);
             if (status == MR_NO_MATCH) {
-                EXEC SQL REPEATED SELECT value INTO :sigwho FROM numvalues
-                 WHERE name='strings_id';
-                sigwho++;
-                EXEC SQL REPEATED UPDATE numvalues SET value = :sigwho
-                 WHERE name='strings_id';
-                INSERT INTO strings (string_id, string) 
-                 VALUES (:sigwho, :name);
+             sigwho=add_string(name);
             } else if (status)
-              return(gdss2et(status));
+              return(status);
             timestamp = si.timestamp;
-        } else
-          return(gdss2et(status));
+        } else {
+           if (log_flags & LOG_GDSS)
+             hex_dump(argv[U_SIGNATURE+1]);
+           return(gdss2et(status));
+       }
     } else {
         rawsig[0] = 0;
         sigwho = 0;
@@ -1849,27 +1901,71 @@ followup_aqot(q, argv, cl)
 {
     EXEC SQL BEGIN DECLARE SECTION;
     int quota, id, fs, who, physid;
-    char *entity, *qtype;
+    char *entity, *qtype, *table_name;
     EXEC SQL END DECLARE SECTION;
+    char incr_qual[60];
+    char *incr_argv[2];
+    int status;
 
+    table_name=q->rtable;
     fs = *(int *)argv[0];
-    if (!strcmp(q->name, "add_quota") || !strcmp(q->name, "update_quota")) {
+    EXEC SQL REPEATED SELECT phys_id INTO :physid FROM filesys
+      WHERE filsys_id = :fs;
+    if(ingres_errno)
+       return(mr_errcode);
+
+    if (!strcmp(q->shortname, "aqot") || !strcmp(q->shortname, "uqot")) {
        qtype = argv[1];
        id = *(int *)argv[2];
        quota = atoi(argv[3]);
+       sprintf(incr_qual,"q.filsys_id = %d",fs);
     } else {
        qtype = "USER";
        id = *(int *)argv[1];
        quota = atoi(argv[2]);
+       sprintf(incr_qual,"q.filsys_id=%d AND q.type='%s' AND q.entity_id=%d",
+               fs,qtype,id);
     }
+
+    /* quota case of incremental_{before|after} only looks at slot 1 */
+    incr_argv[1]=qtype;
+
+    /* Follows one of many possible gross hacks to fix these particular
+     * conflicts between what is possible in the query table and what 
+     * is possible in SQL.    
+     */
+    if(q->type==APPEND) {
+       incremental_clear_before();
+       EXEC SQL INSERT INTO quota 
+           (filsys_id, type, entity_id, quota, phys_id) 
+         VALUES (:fs, :qtype, :id, :quota, :physid);
+       incremental_after(table_name, incr_qual, incr_argv);    
+    } else {
+       incremental_before(table_name, incr_qual, incr_argv);
+       EXEC SQL UPDATE quota SET quota = :quota
+         WHERE filsys_id = :fs AND type = :qtype AND entity_id = :id;
+       status = mr_errcode;
+       incremental_after(table_name, incr_qual, incr_argv);
+    }
+
+    if (ingres_errno)
+       return(mr_errcode);
+    flush_name(argv[0], q->rtable);  
+    if(q->type==APPEND) {
+        EXEC SQL UPDATE tblstats SET appends = appends + 1, modtime = 'now'
+         WHERE table_name = :table_name;
+    } else {
+        EXEC SQL UPDATE tblstats SET updates = updates + 1, modtime = 'now'
+         WHERE table_name = :table_name;
+    }
+       
+    /* Proceed with original followup */
     who = cl->client_id;
     entity = cl->entity;
 
     EXEC SQL REPEATED UPDATE quota
       SET modtime = 'now', modby = :who, modwith = :entity
       WHERE filsys_id = :fs and type = :qtype and entity_id = :id;
-    EXEC SQL REPEATED SELECT phys_id INTO :physid FROM filesys
-      WHERE filsys_id = :fs;
     EXEC SQL REPEATED UPDATE nfsphys SET allocated = allocated + :quota
       WHERE nfsphys_id = :physid;
     if (ingres_errno) return(mr_errcode);
@@ -1877,6 +1973,51 @@ followup_aqot(q, argv, cl)
 }
 
 
+/* Necessitated by the requirement of a correlation name by the incremental
+ * routines, since query table deletes don't provide one. 
+ */
+followup_dqot(q,argv,cl)
+    struct query *q;
+    char **argv;
+    struct client *cl;
+{
+    char *qtype;
+    int id, fs;
+    char *incr_argv[2];
+    EXEC SQL BEGIN DECLARE SECTION; 
+    char incr_qual[80];
+    char *tblname;
+    EXEC SQL END DECLARE SECTION; 
+
+    fs = *(int *)argv[0];
+    if (!strcmp(q->shortname, "dqot")) {
+       qtype = argv[1];
+       id = *(int *)argv[2];
+    } else {
+       qtype = "USER";
+       id = *(int *)argv[1];
+    }
+    sprintf(incr_qual,"q.filsys_id=%d AND q.type='%s' AND q.entity_id=%d",
+           fs,qtype,id);
+
+    /* quota case of incremental_{before|after} only looks at slot 1 */
+    incr_argv[1]=qtype;
+
+    incremental_before(q->rtable, incr_qual, incr_argv);
+    EXEC SQL DELETE FROM quota q WHERE :incr_qual;
+    incremental_clear_after();
+
+    if (ingres_errno) 
+       return(mr_errcode);
+    flush_name(argv[0], q->rtable);
+
+    tblname = q->rtable;
+    EXEC SQL UPDATE tblstats SET deletes = deletes + 1, modtime = 'now'
+      WHERE table_name = :tblname;
+    return(MR_SUCCESS);
+}
+
+
 followup_gpce(q, sq, v, action, actarg, cl)
     struct query *q;
     register struct save_queue *sq;
@@ -2071,13 +2212,7 @@ int set_pobox(q, argv, cl)
          return(MR_BAD_CHAR);
        status = name_to_id(box, "STRING", &id);
        if (status == MR_NO_MATCH) {
-           EXEC SQL REPEATED SELECT value INTO :id FROM numvalues
-             WHERE name='strings_id';
-           id++;
-           EXEC SQL REPEATED UPDATE numvalues SET value = :id
-             WHERE name='strings_id';
-           EXEC SQL INSERT INTO strings (string_id, string)
-             VALUES (:id, :box);
+           id=add_string(box);
        } else if (status)
          return(status);
        EXEC SQL REPEATED UPDATE users SET potype='SMTP', box_id = :id
@@ -2089,7 +2224,7 @@ int set_pobox(q, argv, cl)
 
     set_pobox_modtime(q, argv, cl);
     EXEC SQL REPEATED UPDATE tblstats SET updates = updates+1, modtime='now'
-      WHERE tblstats.table_name='users';
+      WHERE table_name='users';
     if (ingres_errno) return(mr_errcode);
     return(MR_SUCCESS);
 }
@@ -2113,6 +2248,7 @@ get_list_info(q, aargv, cl, action, actarg)
     char maillist[5], grouplist[5], gid_str[6], acl_name[256], desc[256];
     char modtime[27], modby[256], modwith[9];
     int id, rowcount, acl_id, hid, modby_id;
+    char qual[80];
     EXEC SQL END DECLARE SECTION;
     int returned, status;
     struct save_queue *sq, *sq_create();
@@ -2122,9 +2258,15 @@ get_list_info(q, aargv, cl, action, actarg)
     convert_wildcards(name);
 
     sq = sq_create();
+    sprintf(qual,"name LIKE '%s' ESCAPE '*'",name);
+    optimize_sql_stmt(qual);
     EXEC SQL DECLARE csr102 CURSOR FOR SELECT list_id FROM list
-      WHERE name LIKE :name ESCAPE '*';
+      WHERE :qual;
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr102;
+    if (ingres_errno)
+       return(mr_errcode);
     while(1)
     {
         EXEC SQL FETCH csr102 INTO :id;
@@ -2209,7 +2351,7 @@ int add_member_to_list(q, argv, cl)
     client *cl;
 {
     EXEC SQL BEGIN DECLARE SECTION;
-    int id, lid, mid, error, who, ref;
+    int id, lid, mid, error, who, ref, rowcnt;
     char *mtype, dtype[9], *entity;
     EXEC SQL END DECLARE SECTION;
     int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a;
@@ -2222,10 +2364,10 @@ int add_member_to_list(q, argv, cl)
     mtype = argv[1];
     mid = *(int *)argv[2];
     /* if the member is already a direct member of the list, punt */
-    EXEC SQL REPEATED SELECT list_id INTO :idummy FROM imembers
+    EXEC SQL REPEATED SELECT COUNT(list_id) INTO :rowcnt FROM imembers
       WHERE list_id = :lid AND member_id = :mid
        AND member_type = :mtype AND direct = 1;
-    if (sqlca.sqlerrd[2] > 0)
+    if (rowcnt > 0)
       return(MR_EXISTS);
     if (!strcasecmp(mtype, "STRING")) {
        buf = malloc(0);
@@ -2244,7 +2386,11 @@ int add_member_to_list(q, argv, cl)
     EXEC SQL DECLARE csr103 CURSOR FOR
       SELECT list_id, ref_count        FROM imembers
        WHERE member_id = :lid AND member_type='LIST';
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr103;
+    if (ingres_errno)
+       return(mr_errcode);
     while(1) {
        EXEC SQL FETCH csr103 INTO :id, :ref;
        if(sqlca.sqlcode != 0) break;
@@ -2267,7 +2413,11 @@ int add_member_to_list(q, argv, cl)
          SELECT member_id, member_type, ref_count
          FROM imembers
          WHERE list_id = :mid;
+       if (ingres_errno)
+           return(mr_errcode);
        EXEC SQL OPEN csr104;
+       if (ingres_errno)
+           return(mr_errcode);
        while(1) {
            EXEC SQL FETCH csr104 INTO :id, :dtype, :ref;
            if(sqlca.sqlcode != 0) break;
@@ -2308,11 +2458,12 @@ int add_member_to_list(q, argv, cl)
            if (mid == lid && !strcmp(mtype, "LIST")) {
                return(MR_LISTLOOP);
            }
-           EXEC SQL REPEATED SELECT ref_count INTO :idummy FROM imembers
+           EXEC SQL REPEATED SELECT COUNT(ref_count) INTO :rowcnt 
+               FROM imembers
              WHERE list_id = :lid AND member_id = :mid
                AND member_type = :mtype;
            ref = aref[a] * dref[d];
-           if (sqlca.sqlerrd[2] > 0) {
+           if (rowcnt > 0) {
                if (a == 0 && d == 0) {
                    EXEC SQL UPDATE imembers
                      SET ref_count = ref_count+:ref, direct=1
@@ -2374,11 +2525,11 @@ int delete_member_from_list(q, argv, cl)
     mtype = argv[1];
     mid = *(int *)argv[2];
     /* if the member is not a direct member of the list, punt */
-    EXEC SQL REPEATED SELECT list_id INTO :idummy FROM imembers
+    EXEC SQL REPEATED SELECT COUNT(list_id) INTO :cnt FROM imembers
       WHERE list_id = :lid AND member_id = :mid
        AND member_type = :mtype AND direct = 1;
     if (ingres_errno) return(mr_errcode);
-    if (sqlca.sqlcode == 100)
+    if (cnt == 0)
       return(MR_NO_MATCH);
     ancestors[0] = lid;
     aref[0] = 1;
@@ -2386,7 +2537,11 @@ int delete_member_from_list(q, argv, cl)
     EXEC SQL DECLARE csr105 CURSOR FOR
       SELECT list_id, ref_count FROM imembers
        WHERE member_id = :lid AND member_type = 'LIST';
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr105;
+    if (ingres_errno)
+       return(mr_errcode);
     while(1) {
        EXEC SQL FETCH csr105 INTO :id, :ref;
        if(sqlca.sqlcode!=0) break;
@@ -2408,7 +2563,11 @@ int delete_member_from_list(q, argv, cl)
        EXEC SQL DECLARE csr106 CURSOR FOR
          SELECT member_id, member_type, ref_count FROM imembers
            WHERE list_id = :mid;
+       if (ingres_errno)
+           return(mr_errcode);
        EXEC SQL OPEN csr106;
+       if (ingres_errno)
+           return(mr_errcode);
        while(1) {
            EXEC SQL FETCH csr106 INTO :id, :dtype, :ref;
            if(sqlca.sqlcode!=0) break;
@@ -2518,7 +2677,11 @@ int get_ace_use(q, argv, cl, action, actarg)
        EXEC SQL DECLARE csr107 CURSOR FOR
          SELECT list_id FROM imembers
            WHERE member_type='LIST' AND member_id = :aid;
+       if (ingres_errno)
+           return(mr_errcode);
        EXEC SQL OPEN csr107;
+       if (ingres_errno)
+           return(mr_errcode);
        while(1) {
            EXEC SQL FETCH csr107 INTO :listid;
            if(sqlca.sqlcode != 0) break;
@@ -2536,7 +2699,11 @@ int get_ace_use(q, argv, cl, action, actarg)
        EXEC SQL DECLARE csr108 CURSOR FOR
          SELECT list_id FROM imembers
            WHERE member_type='USER' AND member_id = :aid;
+       if (ingres_errno)
+           return(mr_errcode);
        EXEC SQL OPEN csr108;
+       if (ingres_errno)
+           return(mr_errcode);
        while(1) {
            EXEC SQL FETCH csr108 INTO :listid;
            if(sqlca.sqlcode != 0) break;
@@ -2556,7 +2723,11 @@ int get_ace_use(q, argv, cl, action, actarg)
        EXEC SQL DECLARE csr109 CURSOR FOR
          SELECT list_id FROM imembers
            WHERE member_type='KERBEROS' AND member_id = :aid;
+       if (ingres_errno)
+           return(mr_errcode);
        EXEC SQL OPEN csr109;
+       if (ingres_errno)
+           return(mr_errcode);
        while(1) {
            EXEC SQL FETCH csr109 INTO :listid;
            if(sqlca.sqlcode != 0) break;
@@ -2604,7 +2775,11 @@ get_ace_internal(atype, aid, action, actarg)
        EXEC SQL DECLARE csr110 CURSOR FOR
          SELECT label FROM filesys
            WHERE owners = :aid;
+       if (ingres_errno)
+           return(mr_errcode);
        EXEC SQL OPEN csr110;
+       if (ingres_errno)
+           return(mr_errcode);
        while(1) {
            EXEC SQL FETCH csr110 INTO :name;
            if(sqlca.sqlcode != 0) break;
@@ -2617,7 +2792,11 @@ get_ace_internal(atype, aid, action, actarg)
        EXEC SQL DECLARE csr111 CURSOR FOR
          SELECT capability FROM capacls
            WHERE list_id = :aid ;
+       if (ingres_errno)
+           return(mr_errcode);
        EXEC SQL OPEN csr111;
+       if (ingres_errno)
+           return(mr_errcode);
        while(1) {
            EXEC SQL FETCH csr111 INTO :name ;
            if(sqlca.sqlcode != 0) break;
@@ -2630,7 +2809,11 @@ get_ace_internal(atype, aid, action, actarg)
        EXEC SQL DECLARE csr112 CURSOR FOR
          SELECT label FROM filesys
            WHERE owner = :aid;
+       if (ingres_errno)
+           return(mr_errcode);
        EXEC SQL OPEN csr112;
+       if (ingres_errno)
+           return(mr_errcode);
        while(1) {
            EXEC SQL FETCH csr112 INTO :name ;
            if(sqlca.sqlcode != 0) break;
@@ -2644,7 +2827,11 @@ get_ace_internal(atype, aid, action, actarg)
     EXEC SQL DECLARE csr113 CURSOR FOR
       SELECT name FROM list
        WHERE acl_type = :atype AND acl_id = :aid;
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr113;
+    if (ingres_errno)
+       return(mr_errcode);
     while(1) {
        EXEC SQL FETCH csr113 INTO :name;
        if(sqlca.sqlcode != 0) break;
@@ -2657,7 +2844,11 @@ get_ace_internal(atype, aid, action, actarg)
     EXEC SQL DECLARE csr114 CURSOR FOR
       SELECT name FROM servers
        WHERE acl_type = :atype AND acl_id = :aid;
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr114;
+    if (ingres_errno)
+       return(mr_errcode);
     while(1) {
        EXEC SQL FETCH csr114 INTO :name;
        if(sqlca.sqlcode != 0) break;
@@ -2671,7 +2862,11 @@ get_ace_internal(atype, aid, action, actarg)
       SELECT name FROM machine m, hostaccess ha
        WHERE m.mach_id = ha.mach_id AND ha.acl_type = :atype
          AND ha.acl_id = :aid;
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr115;
+    if (ingres_errno)
+       return(mr_errcode);
     while(1) {
        EXEC SQL FETCH csr115 INTO :name;
        if(sqlca.sqlcode != 0) break;
@@ -2687,7 +2882,11 @@ get_ace_internal(atype, aid, action, actarg)
          OR z.sub_type = :atype AND z.sub_id = :aid
          OR z.iws_type = :atype AND z.iws_id = :aid
           OR z.iui_type = :atype AND z.iui_id = :aid;
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr116;
+    if (ingres_errno)
+       return(mr_errcode);
     while(1) {
        EXEC SQL FETCH csr116 INTO :name;
        if(sqlca.sqlcode != 0) break;
@@ -2756,7 +2955,11 @@ int get_lists_of_member(q, argv, cl, action, actarg)
            FROM list l, imembers im
            WHERE l.list_id = im.list_id AND im.direct = 1
              AND im.member_type = :atype AND im.member_id = :aid;
+       if (ingres_errno)
+           return(mr_errcode);
        EXEC SQL OPEN csr117a;
+       if (ingres_errno)
+           return(mr_errcode);
        while(1) {
            EXEC SQL FETCH csr117a
              INTO :name, :active, :public, :hidden, :maillist, :grouplist;
@@ -2772,7 +2975,11 @@ int get_lists_of_member(q, argv, cl, action, actarg)
            FROM list l, imembers im
            WHERE l.list_id = im.list_id
              AND im.member_type = :atype AND im.member_id = :aid;
+       if (ingres_errno)
+           return(mr_errcode);
        EXEC SQL OPEN csr117b;
+       if (ingres_errno)
+           return(mr_errcode);
        while(1) {
            EXEC SQL FETCH csr117b
              INTO :name, :active, :public, :hidden, :maillist, :grouplist;
@@ -2872,7 +3079,11 @@ gmol_internal(q, argv, cl, action, actarg, flag)
     EXEC SQL DECLARE csr118 CURSOR FOR
       SELECT member_type, member_id FROM imembers
        WHERE list_id = :list_id AND direct > :direct;
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr118;
+    if (ingres_errno)
+       return(mr_errcode);
     while(1) {
        EXEC SQL FETCH csr118 INTO :member_type, :member_id;
        if (sqlca.sqlcode != 0) break;
@@ -2924,7 +3135,11 @@ gmol_internal(q, argv, cl, action, actarg, flag)
        WHERE im.list_id = :list_id AND im.member_type = 'USER'
          AND im.member_id = u.users_id AND im.direct > :direct
        ORDER BY 1;
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr119;
+    if (ingres_errno)
+       return(mr_errcode);
     while(1) {
        EXEC SQL FETCH csr119 INTO :member_name;
        if(sqlca.sqlcode != 0) break;
@@ -2939,7 +3154,11 @@ gmol_internal(q, argv, cl, action, actarg, flag)
        WHERE im.list_id = :list_id AND im.member_type='LIST'
          AND im.member_id = l.list_id AND im.direct > :direct
         ORDER BY 1;
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr120;
+    if (ingres_errno)
+       return(mr_errcode);
     while(1) {
        EXEC SQL FETCH csr120 INTO :member_name;
        if(sqlca.sqlcode != 0) break;
@@ -2950,11 +3169,15 @@ gmol_internal(q, argv, cl, action, actarg, flag)
 
     targv[0] = "STRING";
     EXEC SQL DECLARE csr121 CURSOR FOR
-      SELECT str.string FROM strings str, imembers im
+      SELECT CHAR(str.string) FROM strings str, imembers im
        WHERE im.list_id = :list_id AND im.member_type='STRING'
          AND im.member_id = str.string_id AND im.direct > :direct
        ORDER BY 1;
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr121;
+    if (ingres_errno)
+       return(mr_errcode);
     while(1) {
        EXEC SQL FETCH csr121 INTO :member_name;
        if(sqlca.sqlcode != 0) break;
@@ -2965,12 +3188,16 @@ gmol_internal(q, argv, cl, action, actarg, flag)
 
     targv[0] = "KERBEROS";
     EXEC SQL DECLARE csr122 CURSOR FOR
-      SELECT strings.string FROM strings, imembers
-       WHERE imembers.list_id = :list_id AND imembers.member_type='KERBEROS'
-         AND imembers.member_id = strings.string_id 
-         AND imembers.direct > :direct
+      SELECT CHAR(str.string) FROM strings str, imembers im
+       WHERE im.list_id = :list_id AND im.member_type='KERBEROS'
+         AND im.member_id = str.string_id 
+         AND im.direct > :direct
        ORDER BY 1;
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr122;
+    if (ingres_errno)
+       return(mr_errcode);
     while(1) {
        EXEC SQL FETCH csr122 INTO :member_name;
        if(sqlca.sqlcode != 0) break;
@@ -3065,7 +3292,7 @@ int qualified_get(q, argv, action, actarg, start, range, field, flags)
     }
 
     rargv[0] = SQLDA->sqlvar[0].sqldata;
-    sprintf(stmt_buf,"SELECT %s.%s FROM %s %s WHERE %s",q->rtable,field,q->rtable,q->rvar,qual); /** Should first rtabl be rvar ??? **/
+    sprintf(stmt_buf,"SELECT CHAR(%s.%s) FROM %s %s WHERE %s",range,field,q->rtable,range,qual);
     EXEC SQL PREPARE stmt INTO :SQLDA USING NAMES FROM :stmt_buf;
     if(sqlca.sqlcode)
       return(MR_INTERNAL);
@@ -3107,7 +3334,6 @@ int qualified_get_serverhost(q, argv, cl, action, actarg)
     char *rargv[2], buf[32];
     int i, rowcount;
 
-    /** the uppercase() function is INGRES-specific */
     sprintf(qual, "m.mach_id = sh.mach_id AND sh.service = uppercase('%s')",
            argv[0]);
     for (i = 1; i < q->argc; i++) {
@@ -3125,7 +3351,11 @@ int qualified_get_serverhost(q, argv, cl, action, actarg)
     EXEC SQL DECLARE csr124 CURSOR FOR
       SELECT sh.service, m.name FROM serverhosts sh, machine m
        WHERE :qual;
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr124;
+    if (ingres_errno)
+       return(mr_errcode);
     while(1) {
         EXEC SQL FETCH csr124 INTO :sname, :mname;
        if(sqlca.sqlcode != 0) break;
@@ -3179,18 +3409,18 @@ register_user(q, argv, cl)
       return(MR_NOT_UNIQUE);
 
     /* check new login name */
-    EXEC SQL REPEATED SELECT login INTO :cdummy FROM users
-      WHERE login = LEFT(:login,SIZE(login)) AND users_id != :users_id;
+    EXEC SQL REPEATED SELECT COUNT(login) INTO :rowcount FROM users
+      WHERE login = :login AND users_id != :users_id;
     if (ingres_errno) return(mr_errcode);
-    if (sqlca.sqlerrd[2] > 0) return(MR_IN_USE);
-    EXEC SQL REPEATED SELECT name INTO :cdummy FROM list
-      WHERE name = LEFT(:login,SIZE(name));
+    if (rowcount > 0) return(MR_IN_USE);
+    EXEC SQL REPEATED SELECT COUNT(name) INTO :rowcount FROM list
+      WHERE name = :login;
     if (ingres_errno) return(mr_errcode);
-    if (sqlca.sqlerrd[2] > 0) return(MR_IN_USE);
-    EXEC SQL REPEATED SELECT label INTO :cdummy FROM filesys
-      WHERE label = LEFT(:login,SIZE(label));
+    if (rowcount > 0) return(MR_IN_USE);
+    EXEC SQL REPEATED SELECT COUNT(label) INTO :rowcount FROM filesys
+      WHERE label = :login;
     if (ingres_errno) return(mr_errcode);
-    if (sqlca.sqlerrd[2] > 0) return(MR_IN_USE);
+    if (rowcount > 0) return(MR_IN_USE);
     com_err(whoami, 0, "login name OK");
 
     /* choose place for pobox, put in mid */
@@ -3200,7 +3430,11 @@ register_user(q, argv, cl)
        AND sh.value2 - sh.value1 =
          (SELECT MAX(value2 - value1) FROM serverhosts
            WHERE service = 'POP');
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL OPEN csr130;
+    if (ingres_errno)
+       return(mr_errcode);
     EXEC SQL FETCH csr130 INTO :mid, :machname;
     if (sqlca.sqlerrd[2] == 0) {
        EXEC SQL CLOSE csr130;
@@ -3303,11 +3537,12 @@ register_user(q, argv, cl)
 
     /* set quota */
     if (def_quota == 0) {
-       EXEC SQL REPEATED SELECT value INTO :quota FROM numvalues
+       EXEC SQL REPEATED SELECT value INTO :def_quota FROM numvalues
          WHERE name='def_quota';
        if (ingres_errno) return(mr_errcode);
        if (sqlca.sqlerrd[2] != 1)
          return(MR_NO_QUOTA);
+       
     }
     incremental_clear_before();
     EXEC SQL REPEATED INSERT INTO quota
@@ -3361,6 +3596,22 @@ static int set_pop_usage(id, cnt)
     return(MR_SUCCESS);
 }
 
+int _sdl_followup(q, argv, cl)
+    struct query *q;
+    char **argv;
+    client *cl;
+{
+    int i;
+    i = atoi(argv[0]);
+    log_flags = i;
+    if (i & LOG_SQL) {
+       EXEC SQL set printqry;
+    } else {
+       EXEC SQL set noprintqry;
+    }
+    return(MR_SUCCESS);
+}
+
 
 \f
 /* Validation Routines */
@@ -3548,11 +3799,7 @@ validate_id(q, argv, vo)
            return(MR_EXISTS);
        } else if (status == MR_NO_MATCH && !strcmp(tbl, "strings") &&
                   (q->type == APPEND || q->type == UPDATE)) {
-           EXEC SQL SELECT value INTO :id FROM numvalues
-             WHERE name = 'strings_id';
-           id++;
-           EXEC SQL UPDATE numvalues SET value = :id WHERE name = 'string_id';
-           EXEC SQL INSERT INTO strings (string_id, string) VALUES (:id, :name);
+           id=add_string(name);
            cache_entry(name, "STRING", id);
            *(int *)argv[vo->index] = id;
            return(MR_EXISTS);
@@ -3696,6 +3943,7 @@ validate_type(argv, vo)
     EXEC SQL BEGIN DECLARE SECTION;
     char *typename;
     char *val;
+    int cnt;
     EXEC SQL END DECLARE SECTION;
     register char *c;
 
@@ -3709,10 +3957,10 @@ validate_type(argv, vo)
     /* uppercase type fields */
     for (c = val; *c; c++) if (islower(*c)) *c = toupper(*c);
 
-    EXEC SQL SELECT trans INTO :cdummy FROM alias
+    EXEC SQL SELECT COUNT(trans) INTO :cnt FROM alias
       WHERE name = :typename AND type='TYPE' AND trans = :val;
     if (ingres_errno) return(mr_errcode);
-    return (sqlca.sqlerrd[2] ? MR_EXISTS : vo->error);
+    return (cnt ? MR_EXISTS : vo->error);
 }
 
 /* validate member or type-specific data field */
@@ -3749,6 +3997,8 @@ validate_typedata(q, argv, vo)
        *index(data_type, ' ') = 0;
     if (!strcmp(data_type, "user")) {
        /* USER */
+       if (index(name, '@'))
+         return(MR_USER);
        status = name_to_id(name, data_type, &id);
        if (status && (status == MR_NO_MATCH || status == MR_NOT_UNIQUE))
          return(MR_USER);
@@ -3786,10 +4036,7 @@ validate_typedata(q, argv, vo)
          return(MR_STRING);
        if (status == MR_NO_MATCH) {
            if (q->type != APPEND && q->type != UPDATE) return(MR_STRING);
-           EXEC SQL SELECT value INTO :id FROM numvalues WHERE name = 'strings_id';
-           id++;
-           EXEC SQL UPDATE numvalues SET value = :id WHERE name = 'strings_id';
-           EXEC SQL INSERT INTO strings (string_id, string) VALUES (:id, :name);
+           id=add_string(name);
            cache_entry(name, "STRING", id);
        } else if (status) return(status);
     } else if (!strcmp(data_type, "none")) {
@@ -3848,11 +4095,11 @@ MR_SQLDA_T *mr_alloc_SQLDA()
     }
 
     for(j=0; j<QMAXARGS; j++) {
-       if((it->sqlvar[j].sqldata=malloc(sizeof(short)+QMAXARGSIZE))==NULL) {
+       if((it->sqlvar[j].sqldata=malloc(sizeof(short)+ARGLEN))==NULL) {
            com_err(whoami, MR_NO_MEM, "setting up SQLDA variables");
            exit(1);
        }
-       it->sqlvar[j].sqllen=QMAXARGSIZE;
+       it->sqlvar[j].sqllen=ARGLEN;
        it->sqlvar[j].sqlind=null_indicators+j;
        null_indicators[j]=0;
     }
@@ -3958,8 +4205,8 @@ prefetch_filesys(q,argv,cl)
     if(ingres_errno) return(mr_errcode);
 
     argc=q->argc+q->vcnt;
-    sprintf(argv[argc++],"%d",fid);
-    sprintf(argv[argc],"%d",phid);
+    sprintf(argv[argc++],"%d",phid);
+    sprintf(argv[argc],"%d",fid);
 
     return(MR_SUCCESS);
 }
@@ -3968,7 +4215,7 @@ prefetch_filesys(q,argv,cl)
 convert_wildcards(arg)
     char *arg;
 {
-    static char buffer[QMAXARGSIZE];
+    static char buffer[ARGLEN];
     register char *s, *d;
 
     for(d=buffer,s=arg;*s;s++) {
@@ -3998,7 +4245,7 @@ convert_wildcards(arg)
 convert_wildcards_uppercase(arg)
     char *arg;
 {
-    static char buffer[QMAXARGSIZE];
+    static char buffer[ARGLEN];
     register char *s, *d;
 
     for(d=buffer,s=arg;*s;s++) {
@@ -4047,4 +4294,78 @@ mr_select_any(stmt)
 } 
 
 
+
+static hex_dump(p)
+unsigned  char *p;
+{
+    char buf[BUFSIZ];
+    int i;
+
+    fprintf(stderr, "Size: %d\n", strlen(p));
+    while (strlen(p) >= 8) {
+       fprintf(stderr, "%02x %02x %02x %02x %02x %02x %02x %02x\n",
+               p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
+       p += 8;
+    }
+    switch (strlen(p)) {
+    case 7:
+       fprintf(stderr, "%02x %02x %02x %02x %02x %02x %02x\n",
+               p[0], p[1], p[2], p[3], p[4], p[5], p[6]);
+       break;
+    case 6:
+       fprintf(stderr, "%02x %02x %02x %02x %02x %02x\n",
+               p[0], p[1], p[2], p[3], p[4], p[5]);
+       break;
+    case 5:
+       fprintf(stderr, "%02x %02x %02x %02x %02x\n",
+               p[0], p[1], p[2], p[3], p[4]);
+       break;
+    case 4:
+       fprintf(stderr, "%02x %02x %02x %02x\n",
+               p[0], p[1], p[2], p[3]);
+       break;
+    case 3:
+       fprintf(stderr, "%02x %02x %02x\n",
+               p[0], p[1], p[2]);
+       break;
+    case 2:
+       fprintf(stderr, "%02x %02x\n",
+               p[0], p[1]);
+       break;
+    case 1:
+       fprintf(stderr, "%02x\n",
+               p[0]);
+       break;
+    default:
+       return;
+    }
+}
+
+
+
+/*  Adds a string to the string table.  Returns the id number.
+ * 
+ */
+int add_string(name)
+    EXEC SQL BEGIN DECLARE SECTION; 
+    char *name;
+    EXEC SQL END DECLARE SECTION;
+{
+    EXEC SQL BEGIN DECLARE SECTION;
+    char buf[256];
+    int id;
+    EXEC SQL END DECLARE SECTION; 
+
+    EXEC SQL SELECT value INTO :id FROM numvalues WHERE name = 'strings_id';
+    id++;
+    EXEC SQL UPDATE numvalues SET value = :id WHERE name = 'strings_id';
+    
+    /* Use sprintf to get around problem with doubled single quotes */
+    sprintf(buf,"INSERT INTO strings (string_id, string) VALUES (%d, '%s')",id,name);
+    EXEC SQL EXECUTE IMMEDIATE :buf;
+    return(id);
+}
+
+
 /* eof:qsupport.dc */
This page took 0.12854 seconds and 4 git commands to generate.