IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 13, 2007, 11:19:41 AM (18 years ago)
Author:
jhoblitt
Message:

add setflatcorrpRunState()
add database rollbacks where appropriate

File:
1 edited

Legend:

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

    r15583 r15606  
    3636static bool pendingMode(pxConfig *config);
    3737static bool updateMode(pxConfig *config);
     38
     39static bool setflatcorrpRunState(pxConfig *config, psS64 corr_id, const char *state);
    3840
    3941# define MODECASE(caseName, func) \
     
    263265            label
    264266        )) {
     267        if (!psDBRollback(config->dbh)) {
     268            psError(PS_ERR_UNKNOWN, false, "database error");
     269        }
    265270        psError(PS_ERR_UNKNOWN, false, "database error");
    266271        return false;
     
    276281        psS64 exp_id = psMetadataLookupS64(&status, md, "exp_id");
    277282        if (!status) {
     283            if (!psDBRollback(config->dbh)) {
     284                psError(PS_ERR_UNKNOWN, false, "database error");
     285            }
    278286            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for exp_id");
    279287            psFree(output);
     
    298306                chip_id
    299307            )) {
     308            if (!psDBRollback(config->dbh)) {
     309                psError(PS_ERR_UNKNOWN, false, "database error");
     310            }
    300311            psError(PS_ERR_UNKNOWN, false, "database error");
    301312            return false;
     
    305316    psFree(output);
    306317
     318    // set the flatcorrRun to a state of 'run'
     319    if (!setflatcorrpRunState(config, corr_id, "run")) {
     320        if (!psDBRollback(config->dbh)) {
     321            psError(PS_ERR_UNKNOWN, false, "database error");
     322        }
     323        psError(PS_ERR_UNKNOWN, false, "failed to set run state");
     324        return false;
     325    }
     326
    307327    if (!psDBCommit(config->dbh)) {
    308328        psError(PS_ERR_UNKNOWN, false, "database error");
     
    326346    return false;
    327347}
     348
     349
     350static bool setflatcorrpRunState(pxConfig *config, psS64 corr_id, const char *state)
     351{
     352    PS_ASSERT_PTR_NON_NULL(state, false);
     353
     354    // check that state is a valid string value
     355    if (!(
     356            (strncmp(state, "run", 4) == 0)
     357            || (strncmp(state, "stop", 5) == 0)
     358            || (strncmp(state, "reg", 4) == 0)
     359        )
     360    ) {
     361        psError(PS_ERR_UNKNOWN, false, "invalid state: %s", state);
     362        return false;
     363    }
     364
     365    char *query = "UPDATE flatcorrpRun SET state = '%s' WHERE corr_id = %" PRId64;
     366    if (!p_psDBRunQuery(config->dbh, query, state, corr_id)) {
     367        psError(PS_ERR_UNKNOWN, false,
     368                "failed to change state for corr_id %" PRId64, corr_id);
     369        return false;
     370    }
     371
     372    return true;
     373}
Note: See TracChangeset for help on using the changeset viewer.