IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 14, 2008, 6:21:12 PM (18 years ago)
Author:
Paul Price
Message:

Adding magictool -mask (to get the URI for the mask information out). Getting magictool -addmask to update the mask state to 'stop'. Need to be better about magicRun.state and fault throughout.

File:
1 edited

Legend:

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

    r18525 r18526  
    4343static bool tomaskMode(pxConfig *config);
    4444static bool addmaskMode(pxConfig *config);
     45static bool maskMode(pxConfig *config);
    4546
    4647static bool setmagicRunState(pxConfig *config, psS64 magic_id, const char *state);
     
    7778        MODECASE(MAGICTOOL_MODE_TOMASK,         tomaskMode);
    7879        MODECASE(MAGICTOOL_MODE_ADDMASK,        addmaskMode);
     80        MODECASE(MAGICTOOL_MODE_MASK,           maskMode);
    7981        default:
    8082            psAbort("invalid option (this should not happen)");
     
    878880    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
    879881
     882    if (!psDBTransaction(config->dbh)) {
     883        psError(PS_ERR_UNKNOWN, false, "database error");
     884        return false;
     885    }
     886
    880887    if (!magicMaskInsert(config->dbh,
    881888                         (psS64)atoll(magic_id),
     
    887894        return false;
    888895    }
     896
     897    // Set the magicRun state
     898    psString query = pxDataGet("magictool_addmask.sql");
     899    if (!query) {
     900        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     901        return false;
     902    }
     903
     904    // Add "magic_id = value"
     905    psString whereClause = psDBGenerateWhereConditionSQL(config->where, NULL);
     906    psStringAppend(&query, " AND %s", whereClause);
     907    psFree(whereClause);
     908
     909    if (!p_psDBRunQuery(config->dbh, query)) {
     910        psError(PS_ERR_UNKNOWN, false, "database error");
     911        psFree(query);
     912        return false;
     913    }
     914    psFree(query);
     915
     916    if (!psDBCommit(config->dbh)) {
     917        psError(PS_ERR_UNKNOWN, false, "database error");
     918        return false;
     919    }
     920
     921    return true;
     922}
     923
     924
     925static bool maskMode(pxConfig *config)
     926{
     927    PS_ASSERT_PTR_NON_NULL(config, false);
     928
     929    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     930    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     931
     932    psString query = pxDataGet("magictool_mask.sql");
     933    if (!query) {
     934        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     935        return false;
     936    }
     937
     938    if (config->where) {
     939        psString whereClause = psDBGenerateWhereConditionSQL(config->where, NULL);
     940        psStringAppend(&query, " AND %s", whereClause);
     941        psFree(whereClause);
     942    }
     943
     944    // treat limit == 0 as "no limit"
     945    if (limit) {
     946        psString limitString = psDBGenerateLimitSQL(limit);
     947        psStringAppend(&query, " %s", limitString);
     948        psFree(limitString);
     949    }
     950
     951    if (!p_psDBRunQuery(config->dbh, query)) {
     952        psError(PS_ERR_UNKNOWN, false, "database error");
     953        psFree(query);
     954        return false;
     955    }
     956    psFree(query);
     957
     958    psArray *output = p_psDBFetchResult(config->dbh);
     959    if (!output) {
     960        psErrorCode err = psErrorCodeLast();
     961        switch (err) {
     962            case PS_ERR_DB_CLIENT:
     963                psError(PXTOOLS_ERR_SYS, false, "database error");
     964            case PS_ERR_DB_SERVER:
     965                psError(PXTOOLS_ERR_PROG, false, "database error");
     966            default:
     967                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     968        }
     969
     970        return false;
     971    }
     972    if (!psArrayLength(output)) {
     973        psTrace("magictool", PS_LOG_INFO, "no rows found");
     974        psFree(output);
     975        return true;
     976    }
     977
     978    if (psArrayLength(output)) {
     979        // negative simple so the default is true
     980        if (!ippdbPrintMetadatas(stdout, output, "magicNode", !simple)) {
     981            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     982            psFree(output);
     983            return false;
     984        }
     985    }
     986
     987    psFree(output);
    889988
    890989    return true;
Note: See TracChangeset for help on using the changeset viewer.