IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16362


Ignore:
Timestamp:
Feb 7, 2008, 3:54:05 PM (18 years ago)
Author:
jhoblitt
Message:

implement pztool -copied

Location:
trunk/ippTools/src
Files:
2 edited

Legend:

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

    r16360 r16362  
    651651{
    652652    PS_ASSERT_PTR_NON_NULL(config, false);
     653
     654    psMetadata *where = psMetadataAlloc();
     655
     656    PXOPT_COPY_STR(config->args, where,  "-exp_name", "exp_name", "==");
     657    PXOPT_COPY_STR(config->args, where, "-inst", "inst", "==");
     658    PXOPT_COPY_STR(config->args, where, "-telescope", "telescope", "==");
     659    PXOPT_COPY_STR(config->args, where,  "-class", "class", "==");
     660    PXOPT_COPY_STR(config->args, where,  "-class_id", "class_id", "==");
     661
     662    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     663    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     664    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
     665
     666    psString query = psStringCopy("SELECT * FROM pzDoneImfile");
     667
     668    if (faulted) {
     669        // list only faulted rows
     670        psStringAppend(&query, " %s", "WHERE pzDoneImfile.fault != 0");
     671    } else {
     672        // don't list faulted rows
     673        psStringAppend(&query, " %s", "WHERE pzDoneImfile.fault = 0");
     674    }
     675
     676    if (psListLength(where->list)) {
     677        psString whereClause = psDBGenerateWhereConditionSQL(where, "pzDoneImfile");
     678        psStringAppend(&query, " AND %s", whereClause);
     679        psFree(whereClause);
     680    }
     681    psFree(where);
     682
     683    // treat limit == 0 as "no limit"
     684    if (limit) {
     685        psString limitString = psDBGenerateLimitSQL(limit);
     686        psStringAppend(&query, " %s", limitString);
     687        psFree(limitString);
     688    }
     689
     690    if (!p_psDBRunQuery(config->dbh, query)) {
     691        psError(PS_ERR_UNKNOWN, false, "database error");
     692        psFree(query);
     693        return false;
     694    }
     695    psFree(query);
     696
     697    psArray *output = p_psDBFetchResult(config->dbh);
     698    if (!output) {
     699        psError(PS_ERR_UNKNOWN, false, "database error");
     700        return false;
     701    }
     702    if (!psArrayLength(output)) {
     703        psTrace("pztool", PS_LOG_INFO, "no rows found");
     704        psFree(output);
     705        return true;
     706    }
     707
     708    // negative simple so the default is true
     709    if (!ippdbPrintMetadatas(stdout, output, "chipPendingImfile", !simple)) {
     710        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     711        psFree(output);
     712        return false;
     713    }
     714
     715    psFree(output);
     716
    653717    return true;
    654718}
  • trunk/ippTools/src/pztoolConfig.c

    r16360 r16362  
    128128    psMetadata *copiedArgs = psMetadataAlloc();
    129129    psMetadataAddStr(copiedArgs, PS_LIST_TAIL, "-exp_name", 0,
    130             "define exposure ID (required)", NULL);
     130            "define exposure ID", NULL);
    131131    psMetadataAddStr(copiedArgs, PS_LIST_TAIL, "-inst", 0,
    132             "define camera ID (required)", NULL);
     132            "define camera ID", NULL);
    133133    psMetadataAddStr(copiedArgs, PS_LIST_TAIL, "-telescope", 0,
    134             "define telescope ID (required)", NULL);
     134            "define telescope ID", NULL);
    135135    psMetadataAddStr(copiedArgs, PS_LIST_TAIL, "-class", 0,
    136136            "define class", NULL);
     
    139139    psMetadataAddBool(copiedArgs, PS_LIST_TAIL, "-faulted",  0,
    140140            "only return imfiles with a fault status set", false);
     141    psMetadataAddU64(copiedArgs, PS_LIST_TAIL, "-limit",  0,
     142            "limit result set to N items", 0);
    141143    psMetadataAddBool(copiedArgs, PS_LIST_TAIL, "-simple",  0,
    142144            "use the simple output format", false);
Note: See TracChangeset for help on using the changeset viewer.