]> andersk Git - moira.git/blobdiff - server/qsupport.dc
missing SRCDIR; ifdef on GDSS
[moira.git] / server / qsupport.dc
index 5ebac61a420280d97f2d6dc6a74956c6c19a2355..21bdf88e3c111262584b8fc80f4c5c8bcdb8860b 100644 (file)
@@ -913,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;
@@ -1070,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);
@@ -1536,13 +1535,7 @@ 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';
-                EXEC SQL INSERT INTO strings (string_id, string) 
-                 VALUES (:sigwho, :name);
+             sigwho=add_string(name);
             } else if (status)
               return(status);
             timestamp = si.timestamp;
@@ -1646,13 +1639,7 @@ 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';
-                EXEC SQL INSERT INTO strings (string_id, string) 
-                 VALUES (:sigwho, :name);
+             sigwho=add_string(name);
             } else if (status)
               return(status);
             timestamp = si.timestamp;
@@ -2225,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
@@ -2281,7 +2262,11 @@ get_list_info(q, aargv, cl, action, actarg)
     optimize_sql_stmt(qual);
     EXEC SQL DECLARE csr102 CURSOR FOR SELECT list_id FROM list
       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;
@@ -2401,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;
@@ -2424,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;
@@ -2544,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;
@@ -2566,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;
@@ -2676,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;
@@ -2694,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;
@@ -2714,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;
@@ -2762,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;
@@ -2775,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;
@@ -2788,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;
@@ -2802,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;
@@ -2815,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;
@@ -2829,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;
@@ -2845,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;
@@ -2914,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;
@@ -2930,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;
@@ -3030,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;
@@ -3082,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;
@@ -3097,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;
@@ -3112,7 +3173,11 @@ gmol_internal(q, argv, cl, action, actarg, flag)
        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;
@@ -3128,7 +3193,11 @@ gmol_internal(q, argv, cl, action, actarg, flag)
          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;
@@ -3282,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;
@@ -3357,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;
@@ -3722,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 = 'strings_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);
@@ -3963,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")) {
@@ -4271,4 +4341,31 @@ unsigned  char *p;
     }
 }
 
+
+
+/*  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.04866 seconds and 4 git commands to generate.