]> andersk Git - moira.git/blobdiff - server/qsupport.dc
Further changes to prevent INGRES error 40100.
[moira.git] / server / qsupport.dc
index 914b0f4b498fb3ea8083f7e030a32f367fd09f02..3f57ea54c3f54cfce0c8b062921b9746dc8a67ba 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);
@@ -802,10 +801,10 @@ 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 (ok == 0) return(MR_FILESYS_ACCESS);
 
     if((mr_errcode=prefetch_value(q,argv,cl))!=MR_SUCCESS)
       return(mr_errcode);
@@ -830,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];
@@ -844,10 +844,10 @@ 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;
@@ -864,10 +864,10 @@ setup_ufil(q, argv, cl)
        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",
@@ -981,16 +981,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 label 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);
@@ -1049,6 +1049,7 @@ setup_sshi(q, argv, cl)
     EXEC SQL set lockmode session where readlock = system;
 #endsql
 #endif
+    return(MR_SUCCESS);
 }
 
 
@@ -2248,6 +2249,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();
@@ -2257,8 +2259,10 @@ 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;
     EXEC SQL OPEN csr102;
     while(1)
     {
@@ -2344,7 +2348,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;
@@ -2357,10 +2361,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);
@@ -2443,11 +2447,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
@@ -2509,11 +2514,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;
@@ -3313,18 +3318,18 @@ register_user(q, argv, cl)
       return(MR_NOT_UNIQUE);
 
     /* check new login name */
-    EXEC SQL REPEATED SELECT login INTO :cdummy FROM users
+    EXEC SQL REPEATED SELECT COUNT(login) INTO :rowcount FROM users
       WHERE login = LEFT(:login,SIZE(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
+    if (rowcount > 0) return(MR_IN_USE);
+    EXEC SQL REPEATED SELECT COUNT(name) INTO :rowcount FROM list
       WHERE name = LEFT(:login,SIZE(name));
     if (ingres_errno) return(mr_errcode);
-    if (sqlca.sqlerrd[2] > 0) return(MR_IN_USE);
-    EXEC SQL REPEATED SELECT label INTO :cdummy FROM filesys
+    if (rowcount > 0) return(MR_IN_USE);
+    EXEC SQL REPEATED SELECT COUNT(label) INTO :rowcount FROM filesys
       WHERE label = LEFT(:login,SIZE(label));
     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 */
@@ -3831,6 +3836,7 @@ validate_type(argv, vo)
     EXEC SQL BEGIN DECLARE SECTION;
     char *typename;
     char *val;
+    int cnt;
     EXEC SQL END DECLARE SECTION;
     register char *c;
 
@@ -3844,10 +3850,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 */
This page took 0.069094 seconds and 4 git commands to generate.