IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 5, 2008, 4:29:29 PM (18 years ago)
Author:
jhoblitt
Message:

misc faketool fixups
add faketool -pendingexp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/faketool/ippTools/src/faketool.c

    r17938 r17957  
    3535static bool queueMode(pxConfig *config);
    3636static bool updaterunMode(pxConfig *config);
     37static bool pendingexpMode(pxConfig *config);
    3738static bool pendingimfileMode(pxConfig *config);
    3839static bool addprocessedimfileMode(pxConfig *config);
     
    6667        MODECASE(FAKETOOL_MODE_QUEUE,                   queueMode);
    6768        MODECASE(FAKETOOL_MODE_UPDATERUN,               updaterunMode);
     69        MODECASE(FAKETOOL_MODE_PENDINGEXP,              pendingexpMode);
    6870        MODECASE(FAKETOOL_MODE_PENDINGIMFILE,           pendingimfileMode);
    6971        MODECASE(FAKETOOL_MODE_ADDPROCESSEDIMFILE,      addprocessedimfileMode);
     
    178180
    179181    if (where && psListLength(where->list)) {
    180         psString whereClause = psDBGenerateWhereConditionSQL(where, "camRun");
    181         psStringAppend(&query, " AND %s", whereClause);
     182        psString whereClause = psDBGenerateWhereSQL(where, NULL);
     183        psStringAppend(&query, " %s", whereClause);
    182184        psFree(whereClause);
    183185    }
     
    353355
    354356
     357static bool pendingexpMode(pxConfig *config)
     358{
     359    PS_ASSERT_PTR_NON_NULL(config, false);
     360
     361    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     362    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     363
     364    psMetadata *where = psMetadataAlloc();
     365    PXOPT_COPY_STR(config->args, where, "-fake_id", "fake_id", "==");
     366    PXOPT_COPY_STR(config->args, where, "-cam_id", "cam_id", "==");
     367    PXOPT_COPY_STR(config->args, where, "-chip_id", "chip_id", "==");
     368
     369    psString query = pxDataGet("faketool_find_pendingexp.sql");
     370    if (!query) {
     371        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     372        psFree(where);
     373        return false;
     374    }
     375
     376    if (where && psListLength(where->list)) {
     377        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     378        psStringAppend(&query, " AND %s", whereClause);
     379        psFree(whereClause);
     380    }
     381    psFree(where);
     382
     383    // treat limit == 0 as "no limit"
     384    if (limit) {
     385        psString limitString = psDBGenerateLimitSQL(limit);
     386        psStringAppend(&query, " %s", limitString);
     387        psFree(limitString);
     388    }
     389
     390    if (!p_psDBRunQuery(config->dbh, query)) {
     391        psError(PS_ERR_UNKNOWN, false, "database error");
     392        psFree(query);
     393        return false;
     394    }
     395    psFree(query);
     396
     397    psArray *output = p_psDBFetchResult(config->dbh);
     398    if (!output) {
     399        psError(PS_ERR_UNKNOWN, false, "database error");
     400        return false;
     401    }
     402    if (!psArrayLength(output)) {
     403        psTrace("camtool", PS_LOG_INFO, "no rows found");
     404        psFree(output);
     405        return true;
     406    }
     407
     408    if (!convertIdToStr(output)) {
     409        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
     410        psFree(output);
     411        return false;
     412    }
     413
     414    // negate simple so the default is true
     415    if (!ippdbPrintMetadatas(stdout, output, "fakePendingExp", !simple)) {
     416        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     417        psFree(output);
     418        return false;
     419    }
     420
     421    psFree(output);
     422
     423    return true;
     424}
     425
     426
    355427static bool pendingimfileMode(pxConfig *config)
    356428{
     
    705777    PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
    706778
    707     if (!pxSetFaultCode(config->dbh, "fakeProcessedImfile", config->where, code)) {
     779    psMetadata *where = psMetadataAlloc();
     780    PXOPT_LOOKUP_STR(fake_id, config->args, "-fake_id", false, false);
     781    // convert fake_id into a psS64
     782    if (fake_id) {
     783        if (!psMetadataAddS64(where, PS_LIST_TAIL, "fake_id", 0, "==", (psS64)atoll(fake_id))) {
     784            psError(PS_ERR_UNKNOWN, false, "failed to add item fake_id");
     785            psFree(where);
     786            return false;
     787        }
     788    }
     789    PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "==");
     790
     791    if (!pxSetFaultCode(config->dbh, "fakeProcessedImfile", where, code)) {
    708792        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
    709         return false;
    710     }
     793        psFree(where);
     794        return false;
     795    }
     796    psFree(where);
    711797
    712798    return true;
Note: See TracChangeset for help on using the changeset viewer.