IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 14, 2006, 5:51:39 PM (20 years ago)
Author:
jhoblitt
Message:

fix SQL quries in pendingexpMode() & updateimfileMode() to handle multiple newExp rows

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/regtool.c

    r8329 r8341  
    6969
    7070    char *query =
    71         "SELECT newExp.* FROM newExp"
     71        "SELECT newExp.*"
     72        "   FROM newExp"
     73        " LEFT JOIN newImfile USING(exp_id)"
    7274        " LEFT JOIN rawScienceExp USING(exp_id)"
    73         " LEFT JOIN rawDetrendExp USING (exp_id)"
    74         " LEFT JOIN newImfile USING (exp_id)"
    75         " WHERE newExp.exp_id is NOT NULL"
    76         " AND rawScienceExp.exp_id IS NULL"
    77         " AND rawDetrendExp.exp_id IS NULL"
    78         " AND newImfile.exp_id IS NULL"
    79         " AND newExp.imfiles = (SELECT COUNT(exp_id)"
    80                                 " FROM rawImfile GROUP BY exp_id)";
     75        " LEFT JOIN rawDetrendExp USING(exp_id)"
     76        " WHERE"
     77        "   newExp.exp_id IS NOT NULL"
     78        "   AND newImfile.exp_id IS NULL"
     79        "   AND rawScienceExp.exp_id IS NULL"
     80        "   AND newExp.imfiles ="
     81        "   (SELECT COUNT(exp_id) FROM rawImfile"
     82        "       WHERE rawImfile.exp_id = newExp.exp_id)"
     83        ;
    8184
    8285    if (!p_psDBRunQuery(config->dbh, query)) {
     
    176179    // exp_id is not in newImfile
    177180    // that the correct count of imfiles is in rawImfile
    178     psString query = psStringCopy("SELECT newExp.* FROM newExp LEFT JOIN newImfile USING(exp_id) LEFT JOIN rawScienceExp USING(exp_id) LEFT JOIN rawDetrendExp USING(exp_id) WHERE newExp.exp_id IS NOT NULL AND newImfile.exp_id IS NULL AND rawScienceExp.exp_id IS NULL AND newExp.imfiles = (SELECT COUNT(exp_id) FROM rawImfile GROUP BY exp_id)");
     181
     182    psString query = psStringCopy(
     183        "SELECT newExp.*"
     184        "   FROM newExp"
     185        " LEFT JOIN newImfile USING(exp_id)"
     186        " LEFT JOIN rawScienceExp USING(exp_id)"
     187        " LEFT JOIN rawDetrendExp USING(exp_id)"
     188        " WHERE"
     189        "   newExp.exp_id IS NOT NULL"
     190        "   AND newImfile.exp_id IS NULL"
     191        "   AND rawScienceExp.exp_id IS NULL"
     192        "   AND newExp.imfiles ="
     193        "   (SELECT COUNT(exp_id) FROM rawImfile"
     194        "       WHERE rawImfile.exp_id = newExp.exp_id)"
     195        );
    179196
    180197    {       
     
    418435    // XXX search by the whole frame some imfiles without a newExp don't get
    419436    // processed -- this may not be the correct thing to do
    420     char *query =
     437    psString query = psStringCopy(
    421438        "SELECT * FROM"
    422439            " (SELECT newImfile.* FROM newImfile"
     
    427444                " AND rawScienceExp.exp_id IS NULL"
    428445                " AND rawDetrendExp.exp_id IS NULL) AS foo"
    429         " %s"; // WHERE class is generated from exp_id, class, & class_id
     446        ); // WHERE class is generated from exp_id, class, & class_id
    430447
    431448    char *whereClaus = NULL;
     
    437454        if (!status) {
    438455            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id");
     456            psFree(query);
    439457            return false;
    440458        }
     
    443461                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
    444462                psFree(where);
     463                psFree(query);
    445464                return false;
    446465            }
     
    449468        if (!status) {
    450469            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class");
     470            psFree(query);
    451471            return false;
    452472        }
     
    455475                psError(PS_ERR_UNKNOWN, false, "failed to add item class");
    456476                psFree(where);
     477                psFree(query);
    457478                return false;
    458479            }
     
    461482        if (!status) {
    462483            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
     484            psFree(query);
    463485            return false;
    464486        }
     
    467489                psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
    468490                psFree(where);
     491                psFree(query);
    469492                return false;
    470493            }
     
    472495
    473496        // there's not
    474         whereClaus = psDBGenerateWhereSQL(where);
     497        whereClaus = psDBGenerateWhereSQL(where, NULL);
    475498        psFree(where);
    476     }
    477 
    478     if (!p_psDBRunQuery(config->dbh, query, whereClaus)) {
     499        if (whereClaus) {
     500            psStringAppend(&query, " %s", whereClaus);
     501            psFree(whereClaus);
     502        }
     503    }
     504
     505    if (!p_psDBRunQuery(config->dbh, query)) {
    479506        psError(PS_ERR_UNKNOWN, false, "database error");
    480         psFree(whereClaus);
    481         return false;
    482     }
    483     psFree(whereClaus);
     507        psFree(query);
     508        return false;
     509    }
     510    psFree(query);
    484511
    485512    psArray *newImfiles = p_psDBFetchResult(config->dbh);
Note: See TracChangeset for help on using the changeset viewer.