IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 21, 2008, 12:12:59 PM (18 years ago)
Author:
eugene
Message:

adding cleanup mode functions (but not yet sql or cmd-line options); dropping guidetool

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080719/ippTools/src/dettool_normalizedstat.c

    r18641 r18643  
    208208    return true;
    209209}
     210
     211bool pendingcleanup_normalizedstatMode(pxConfig *config)
     212{
     213    PS_ASSERT_PTR_NON_NULL(config, NULL);
     214
     215    PXOPT_LOOKUP_S64(chip_id, config->args, "-chip_id", false, false);
     216    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     217    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     218
     219    psMetadata *where = psMetadataAlloc();
     220    if (chip_id) {
     221        PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
     222    }
     223    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     224
     225    psString query = pxDataGet("dettool_pendingcleanup_normalizedstat.sql");
     226    if (!query) {
     227        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     228        return false;
     229    }
     230
     231    if (where && psListLength(where->list)) {
     232        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     233        psStringAppend(&query, " AND %s", whereClause);
     234        psFree(whereClause);
     235    }
     236    psFree(where);
     237
     238    // treat limit == 0 as "no limit"
     239    if (limit) {
     240        psString limitString = psDBGenerateLimitSQL(limit);
     241        psStringAppend(&query, " %s", limitString);
     242        psFree(limitString);
     243    }
     244
     245    if (!p_psDBRunQuery(config->dbh, query)) {
     246        psError(PS_ERR_UNKNOWN, false, "database error");
     247        psFree(query);
     248        return false;
     249    }
     250    psFree(query);
     251
     252    psArray *output = p_psDBFetchResult(config->dbh);
     253    if (!output) {
     254        psError(PS_ERR_UNKNOWN, false, "database error");
     255        return false;
     256    }
     257    if (!psArrayLength(output)) {
     258        psTrace("dettool", PS_LOG_INFO, "no rows found");
     259        psFree(output);
     260        return true;
     261    }
     262
     263    // negative simple so the default is true
     264    if (!ippdbPrintMetadatas(stdout, output, "detPendingCleanup_normalizedstat", !simple)) {
     265        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     266        psFree(output);
     267        return false;
     268    }
     269
     270    psFree(output);
     271
     272    return true;
     273}
     274
     275
     276bool donecleanup_normalizedstatMode(pxConfig *config)
     277{
     278    PS_ASSERT_PTR_NON_NULL(config, NULL);
     279
     280    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     281    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     282
     283    psMetadata *where = psMetadataAlloc();
     284    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     285
     286    psString query = pxDataGet("dettool_donecleanup_normalizedstat.sql");
     287    if (!query) {
     288        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     289        return false;
     290    }
     291
     292    if (where && psListLength(where->list)) {
     293        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     294        psStringAppend(&query, " AND %s", whereClause);
     295        psFree(whereClause);
     296    }
     297    psFree(where);
     298
     299    // treat limit == 0 as "no limit"
     300    if (limit) {
     301        psString limitString = psDBGenerateLimitSQL(limit);
     302        psStringAppend(&query, " %s", limitString);
     303        psFree(limitString);
     304    }
     305
     306    if (!p_psDBRunQuery(config->dbh, query)) {
     307        psError(PS_ERR_UNKNOWN, false, "database error");
     308        psFree(query);
     309        return false;
     310    }
     311    psFree(query);
     312
     313    psArray *output = p_psDBFetchResult(config->dbh);
     314    if (!output) {
     315        psError(PS_ERR_UNKNOWN, false, "database error");
     316        return false;
     317    }
     318    if (!psArrayLength(output)) {
     319        psTrace("dettool", PS_LOG_INFO, "no rows found");
     320        psFree(output);
     321        return true;
     322    }
     323
     324    // negative simple so the default is true
     325    if (!ippdbPrintMetadatas(stdout, output, "detDoneCleanup_normalizedstat", !simple)) {
     326        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     327        psFree(output);
     328        return false;
     329    }
     330
     331    psFree(output);
     332
     333    return true;
     334}
     335
Note: See TracChangeset for help on using the changeset viewer.