IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 1, 2011, 11:14:07 AM (15 years ago)
Author:
bills
Message:

add pubtool -updaterun. Currently only sets publishRuns.state

File:
1 edited

Legend:

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

    r30376 r30769  
    3737static bool addMode(pxConfig *config);
    3838static bool revertMode(pxConfig *config);
     39static bool updaterunMode(pxConfig *config);
    3940
    4041# define MODECASE(caseName, func) \
     
    6364        MODECASE(PUBTOOL_MODE_ADD, addMode);
    6465        MODECASE(PUBTOOL_MODE_REVERT, revertMode);
     66        MODECASE(PUBTOOL_MODE_UPDATERUN, updaterunMode);
    6567      default:
    6668        psAbort("invalid option (this should not happen)");
     
    459461}
    460462
     463static bool updaterunMode(pxConfig *config)
     464{
     465    PS_ASSERT_PTR_NON_NULL(config, false);
     466
     467    psMetadata *where = psMetadataAlloc(); // WHERE conditions
     468    PXOPT_COPY_S64(config->args, where, "-pub_id", "pub_id", "==");
     469    PXOPT_COPY_S64(config->args, where, "-client_id", "client_id", "==");
     470    PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
     471    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     472    PXOPT_COPY_STR(config->args, where, "-fault", "fault", "==");
     473
     474    PXOPT_LOOKUP_STR(state, config->args, "-set_state",  true, false);
     475
     476    psString query = NULL;              // Query to run
     477    psStringAppend(&query, "UPDATE publishRun LEFT JOIN publishDone using(pub_id) SET state = '%s'", state);
     478
     479    if (psListLength(where->list)) {
     480        psString clause = psDBGenerateWhereConditionSQL(where, NULL);
     481        psStringAppend(&query, "\n WHERE %s", clause);
     482        psFree(clause);
     483    } else {
     484        psError(PS_ERR_UNKNOWN, false, "select arguments are required");
     485        return false;
     486    }
     487    psFree(where);
     488
     489    if (!p_psDBRunQuery(config->dbh, query)) {
     490        psError(PS_ERR_UNKNOWN, false, "Database error");
     491        psFree(query);
     492        return false;
     493    }
     494    psFree(query);
     495
     496    long numUpdated = psDBAffectedRows(config->dbh);
     497    psLogMsg("pubtool", PS_LOG_INFO, "%ld rows updated.", numUpdated);
     498
     499    return true;
     500}
Note: See TracChangeset for help on using the changeset viewer.