IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:41:49 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/tap_branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/tap_branches

  • branches/tap_branches/ippTools/src

    • Property svn:ignore
      •  

        old new  
        1616difftool
        1717disttool
         18dqstatstool
        1819faketool
        1920flatcorr
  • branches/tap_branches/ippTools/src/pstamptool.c

    r25793 r27838  
    5151static bool pendingdependentMode(pxConfig *config);
    5252static bool updatedependentMode(pxConfig *config);
     53static bool revertdependentMode(pxConfig *config);
    5354
    5455# define MODECASE(caseName, func) \
     
    9192        MODECASE(PSTAMPTOOL_MODE_PENDINGDEPENDENT, pendingdependentMode);
    9293        MODECASE(PSTAMPTOOL_MODE_UPDATEDEPENDENT, updatedependentMode);
     94        MODECASE(PSTAMPTOOL_MODE_REVERTDEPENDENT, revertdependentMode);
    9395        default:
    9496            psAbort("invalid option (this should not happen)");
     
    116118    PS_ASSERT_PTR_NON_NULL(config, false);
    117119
    118     PXOPT_LOOKUP_STR(uri,         config->args, "-uri",           true, false);
    119     PXOPT_LOOKUP_STR(outProduct,  config->args, "-out_product",   true, false);
    120     PXOPT_LOOKUP_STR(lastFileset, config->args, "-last_fileset", false, false);
    121     PXOPT_LOOKUP_STR(state,       config->args, "-state",         false, false);
     120    PXOPT_LOOKUP_STR(uri,         config->args, "-set_uri",           true, false);
     121    PXOPT_LOOKUP_STR(outProduct,  config->args, "-set_out_product",   true, false);
     122    PXOPT_LOOKUP_STR(lastFileset, config->args, "-set_last_fileset", false, false);
     123    PXOPT_LOOKUP_STR(state,       config->args, "-set_state",         false, false);
     124    PXOPT_LOOKUP_STR(label,       config->args, "-set_label",         false, false);
     125    PXOPT_LOOKUP_S32(pollInterval, config->args, "-set_poll_interval",false, false);
    122126
    123127    if (!pstampDataStoreInsert(config->dbh,
     
    125129            state,
    126130            lastFileset,
     131            NULL,       // timestamp
     132            label,      // label
    127133            outProduct,
    128             uri
     134            uri,
     135            pollInterval
    129136        )) {
    130137        psError(PS_ERR_UNKNOWN, false, "database error");
     
    142149    PXOPT_COPY_S64(config->args, where, "-ds_id", "ds_id", "==");
    143150
     151    PXOPT_LOOKUP_BOOL(ready, config->args, "-ready", false);
    144152    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    145153
    146154    psString query = pxDataGet("pstamptool_datastore.sql");
    147155    if (!query) {
    148         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     156        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    149157        return false;
    150158    }
     
    156164    }
    157165    psFree(where);
     166    if (ready) {
     167        psStringAppend(&query, " %s", "\nAND TIMESTAMPDIFF(SECOND, timestamp, now()) > pollInterval");
     168    }
    158169
    159170    if (!p_psDBRunQuery(config->dbh, query)) {
     
    189200
    190201    PXOPT_LOOKUP_S64(ds_id,       config->args, "-ds_id",         true, false);
    191     PXOPT_LOOKUP_STR(lastFileset, config->args, "-last_fileset",  false, false);
    192     PXOPT_LOOKUP_STR(state,       config->args, "-state",         false, false);
    193 
    194     if (!state && !lastFileset) {
    195         psError(PS_ERR_UNKNOWN, true, "at least one of -last_fileset or -state is required");
    196         return false;
    197     }
    198 
    199     char *query = psStringCopy ("UPDATE pstampDataStore SET");
    200     bool needComma = false;
    201    
     202    PXOPT_LOOKUP_STR(lastFileset, config->args, "-set_last_fileset",  false, false);
     203    PXOPT_LOOKUP_STR(state,       config->args, "-set_state",         false, false);
     204    PXOPT_LOOKUP_STR(label,       config->args, "-set_label",         false, false);
     205    PXOPT_LOOKUP_S32(pollInterval, config->args, "-set_poll_interval",         false, false);
     206    PXOPT_LOOKUP_BOOL(update_timestamp, config->args, "-update_timestamp", false);
     207
     208    if (!state && !lastFileset && !pollInterval && !update_timestamp && !label) {
     209        psError(PS_ERR_UNKNOWN, true, "at least one of -last_fileset or -set_state is required");
     210        return false;
     211    }
     212
     213    char *query = psStringCopy ("UPDATE pstampDataStore SET timestamp = CURRENT_TIMESTAMP() ");
     214
    202215    if (lastFileset) {
    203         psStringAppend(&query, " lastFileset = '%s'", lastFileset);
    204         needComma = true;
     216        psStringAppend(&query, " , lastFileset = '%s'", lastFileset);
    205217    }
    206218
    207219    if (state) {
    208         psStringAppend(&query, "%s state = '%s'", needComma ? "," : " ", state);
    209         needComma = true; // be ready in case we add another field
    210     }
    211                
     220        psStringAppend(&query, ", state = '%s'", state);
     221    }
     222
     223    if (label) {
     224        psStringAppend(&query, ", label = '%s'", label);
     225    }
     226
     227    if (pollInterval) {
     228        psStringAppend(&query, ", pollInterval = %d", pollInterval);
     229    }
     230
    212231    psStringAppend(&query, " WHERE ds_id = %" PRId64, ds_id);
    213232
     
    220239    psU64 affected = psDBAffectedRows(config->dbh);
    221240    if (affected != 1) {
    222         psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 
     241        psError(PS_ERR_UNKNOWN, false, "should have affected one row but %"
    223242                                        PRIu64 " rows were modified", affected);
    224243        return false;
     
    245264        label,
    246265        NULL,   // outProduct
    247         uri,   
    248         0       // fault 
     266        uri,
     267        0       // fault
    249268        )) {
    250269        psError(PS_ERR_UNKNOWN, false, "failed to insert request");
     
    265284    psMetadata *where = psMetadataAlloc();
    266285    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
     286    pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE");
    267287
    268288    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     
    271291    psString query = pxDataGet("pstamptool_pendingreq.sql");
    272292    if (!query) {
    273         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     293        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    274294        return false;
    275295    }
     
    342362    psFree(whereClause);
    343363    psFree(where);
    344    
     364
    345365    // treat limit == 0 as "no limit"
    346366    if (limit) {
     
    365385        psTrace("pstamptool", PS_LOG_INFO, "request not found");
    366386        // This causes main to exit with PS_EXIT_DATA_ERROR which the script is looking for
    367         psError(PXTOOLS_ERR_DATA, true, "request not found");
     387        psError(PXTOOLS_ERR_CONFIG, true, "request not found");
    368388        psFree(output);
    369389        // we return false so that the caller can determine that a request does not exist
     
    387407    PS_ASSERT_PTR_NON_NULL(config, false);
    388408
     409    psMetadata *where = psMetadataAlloc();
     410    pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE");
     411
    389412    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    390413    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    391414
    392415    psString query = pxDataGet("pstamptool_completedreq.sql");
     416
     417    if (psListLength(where->list)) {
     418        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     419        psStringAppend(&query, " AND %s", whereClause);
     420        psFree(whereClause);
     421    }
     422    psFree(where);
    393423
    394424    // treat limit == 0 as "no limit"
     
    436466    PXOPT_LOOKUP_STR(state,      config->args, "-state",      false, false);
    437467    PXOPT_LOOKUP_STR(outProduct, config->args, "-outProduct", false, false);
    438     PXOPT_LOOKUP_STR(fault,      config->args, "-fault",      false, false);
    439     PXOPT_LOOKUP_STR(uri,       config->args, "-uri",        false, false);
    440     PXOPT_LOOKUP_STR(name,      config->args, "-name",       false, false);
     468    PXOPT_LOOKUP_S16(fault,      config->args, "-fault",      false, false);
     469    PXOPT_LOOKUP_STR(uri,       config->args, "-uri",        false, false);
     470    PXOPT_LOOKUP_STR(name,      config->args, "-name",       false, false);
    441471    PXOPT_LOOKUP_STR(reqType,    config->args, "-reqType",    false, false);
    442472
     
    454484    }
    455485    if (fault) {
    456         psStringAppend(&query, "%c fault = %s", c, fault);
     486        psStringAppend(&query, "%c fault = %d", c, fault);
    457487        c = ',';
    458488    }
     
    485515    // note zero is not an error
    486516    if (affected > 1) {
    487         psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 
     517        psError(PS_ERR_UNKNOWN, false, "should have affected one row but %"
    488518                                        PRIu64 " rows were modified", affected);
    489519        return false;
     
    500530
    501531    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
    502     PXOPT_COPY_S64(config->args, where, "-fault", "req_id", "==");
     532    PXOPT_COPY_S64(config->args, where, "-fault", "fault", "==");
    503533    PXOPT_COPY_STR(config->args, where, "-state", "pstampRequest.state", "==");
     534    pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "LIKE");
    504535
    505536    if (!psListLength(where->list)) {
    506537        psFree(where);
    507         psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     538        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
    508539        return false;
    509540    }
     
    525556    query = pxDataGet("pstamptool_revertreq.sql");
    526557    psStringAppend(&query, " AND %s", whereClause);
    527    
     558
    528559    psFree(whereClause);
    529560
     
    555586    // unless the job is being inserted with stop state require outputBase
    556587    if (strcmp(stateString, "stop") && !outputBase) {
    557         psError(PS_ERR_UNKNOWN, true, "-outputBase is required");
    558         return false;
     588        psError(PS_ERR_UNKNOWN, true, "-outputBase is required");
     589        return false;
    559590    }
    560591
    561592    // default value for job_type is defined in pstamptoolConfig.c
    562593    if (!strcmp(job_type, "get_image") || !strcmp(job_type, "detect_query") || !strcmp(job_type, "none")) {
    563         stampJob = false;
     594        stampJob = false;
    564595    } else if (!strcmp(job_type, "stamp")) {
    565         stampJob = true;
     596        stampJob = true;
    566597    } else {
    567         psError(PS_ERR_UNKNOWN, false, "unknown value for -job_type: %s", job_type);
    568         return false;
    569     }
    570     if (!pstampJobInsert(config->dbh, 
     598        psError(PS_ERR_UNKNOWN, false, "unknown value for -job_type: %s", job_type);
     599        return false;
     600    }
     601    if (!pstampJobInsert(config->dbh,
    571602            0, // job_id
    572603            req_id,
    573             rownum, 
    574             stateString, 
    575             job_type, 
    576             fault, 
    577             exp_id, 
     604            rownum,
     605            stateString,
     606            job_type,
     607            fault,
     608            exp_id,
    578609            outputBase,
    579610            options,
     
    586617    psU64 affected = psDBAffectedRows(config->dbh);
    587618    if (affected != 1) {
    588         psError(PS_ERR_UNKNOWN, false, 
     619        psError(PS_ERR_UNKNOWN, false,
    589620            "should have affected one row but %" PRIu64 " rows were modified",
    590621            affected);
     
    617648    psString query = pxDataGet("pstamptool_listjob.sql");
    618649    if (!query) {
    619         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     650        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    620651        return false;
    621652    }
     
    674705    PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "==");
    675706    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
     707    pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE");
     708
    676709    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    677710    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     
    679712    psString query = pxDataGet("pstamptool_pendingjob.sql");
    680713    if (!query) {
    681         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     714        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    682715        return false;
    683716    }
     
    685718    // use psDBGenerateWhereSQL because the SQL yields an intermediate table
    686719    if (psListLength(where->list)) {
    687         psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampJob");
     720        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    688721        psStringAppend(&query, " AND %s", whereClause);
    689722        psFree(whereClause);
     
    732765    PS_ASSERT_PTR_NON_NULL(config, false);
    733766
    734     PXOPT_LOOKUP_S64(job_id,    config->args, "-job_id", true, false);
     767    PXOPT_LOOKUP_S64(job_id,    config->args, "-job_id", false, false);
     768    PXOPT_LOOKUP_S64(dep_id,    config->args, "-dep_id", false, false);
     769
     770    if (!job_id && !dep_id) {
     771        psError(PS_ERR_UNKNOWN, true, "at least -job_id or -dep_id is required");
     772        return false;
     773    }
    735774    PXOPT_LOOKUP_STR(state,     config->args, "-state",  true, false);
    736     PXOPT_LOOKUP_STR(fault,     config->args, "-fault",  false, false);
     775    PXOPT_LOOKUP_S32(fault,     config->args, "-fault",  false, false);
     776
     777    psMetadata *where = psMetadataAlloc();
     778
     779    PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "==");
     780    PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "==");
    737781
    738782    psString faultStr = NULL;
     
    740784        faultStr = psStringCopy("");
    741785    } else {
    742         psStringAppend(&faultStr, ", fault = '%s'", fault);
    743     }
    744 
    745     char *query ="UPDATE pstampJob"
    746         " SET state = '%s' %s"
    747         " WHERE job_id = %" PRId64;
    748    
    749     if (!p_psDBRunQueryF(config->dbh, query, state, faultStr, job_id)) {
     786        psStringAppend(&faultStr, "\n, pstampJob.fault = %d", fault);
     787    }
     788
     789    psString query = pxDataGet("pstamptool_updatejob.sql");
     790
     791    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     792    psStringAppend(&query, " WHERE %s", whereClause);
     793    psFree(whereClause);
     794    psFree(where);
     795
     796    if (!p_psDBRunQueryF(config->dbh, query, state, faultStr)) {
    750797        psError(PS_ERR_UNKNOWN, false, "database error");
    751798        psFree(query);
     
    753800    }
    754801    psFree(faultStr);
     802    psFree(query);
    755803
    756804    psU64 affected = psDBAffectedRows(config->dbh);
    757     if (affected != 1) {
    758         psError(PS_ERR_UNKNOWN, false, "should have affected one row but %"
    759                                         PRIu64 " rows were modified", affected);
    760         return false;
    761     }
     805    psLogMsg("pstamptool", PS_LOG_INFO, "Updated %" PRIu64 " pstampJobs", affected);
    762806
    763807    return true;
     
    772816    PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "==");
    773817    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
    774     PXOPT_COPY_S64(config->args, where, "-fault",  "fault", "==");
     818    PXOPT_COPY_S64(config->args, where, "-fault",  "pstampJob.fault", "==");
    775819    PXOPT_COPY_S64(config->args, where, "-req_id_min",  "req_id", ">=");
     820    pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "LIKE");
     821
    776822    PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
    777823    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     824    PXOPT_LOOKUP_S16(fault, config->args, "-fault",  false, false);
     825
     826    // By default only revert faults < 10 which are our "ipp exit codes"
     827    // codes larger than that are the pstamp request interface.
     828    // Don't fault those unless -fault waa provided
     829    psString faultClause = "";
     830    if (!fault) {
     831        faultClause = " \nAND (pstampJob.fault < 10)";
     832    }
    778833
    779834    psString query = pxDataGet("pstamptool_revertjob.sql");
    780835    if (!psListLength(where->list) && !all) {
    781836        psFree(where);
    782         psError(PXTOOLS_ERR_DATA, false, "search parameters or -all are required");
     837        psError(PXTOOLS_ERR_CONFIG, false, "search parameters or -all are required");
    783838        return false;
    784839    }
    785840    if (psListLength(where->list)) {
    786         psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampJob");
     841        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    787842        psStringAppend(&query, " AND %s", whereClause);
    788843        psFree(whereClause);
    789844    }
    790845    psFree(where);
    791    
    792     if (!p_psDBRunQuery(config->dbh, query)) {
     846
     847    if (!p_psDBRunQueryF(config->dbh, query, faultClause)) {
    793848        psError(PS_ERR_UNKNOWN, false, "database error");
    794849        return false;
     
    837892    psString query = pxDataGet("pstamptool_project.sql");
    838893    if (!query) {
    839         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     894        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    840895        return false;
    841896    }
     
    883938
    884939    char *query = psStringCopy ("UPDATE pstampProject SET");
    885    
     940
    886941    psStringAppend(&query, " state = '%s'", state);
    887                
     942
    888943    psStringAppend(&query, " WHERE proj_id = %" PRId64, proj_id);
    889944
     
    896951    psU64 affected = psDBAffectedRows(config->dbh);
    897952    if (affected != 1) {
    898         psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 
     953        psError(PS_ERR_UNKNOWN, false, "should have affected one row but %"
    899954                                        PRIu64 " rows were modified", affected);
    900955        return false;
     
    910965    PXOPT_LOOKUP_STR(stage,       config->args, "-stage",   true, false);
    911966    PXOPT_LOOKUP_S64(stage_id,    config->args, "-stage_id", true, false);
     967    PXOPT_LOOKUP_STR(component,   config->args, "-component",  true, false);
    912968    PXOPT_LOOKUP_STR(imagedb,     config->args, "-imagedb",  true, false);
    913     PXOPT_LOOKUP_STR(rlabel,      config->args, "-rlabel",  false, false);
    914     PXOPT_LOOKUP_BOOL(no_magic,   config->args, "-no_magic", false);
     969    PXOPT_LOOKUP_STR(rlabel,      config->args, "-rlabel",  true, false);
     970    PXOPT_LOOKUP_BOOL(need_magic, config->args, "-need_magic", false);
    915971    PXOPT_LOOKUP_BOOL(no_create,  config->args, "-no_create", false);
    916972
    917     psString query = pxDataGet("pstamptool_pendingdependent.sql");
     973    psMetadata *where = psMetadataAlloc();
     974    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     975    PXOPT_COPY_STR(config->args, where, "-imagedb", "imagedb", "==");
     976    PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
     977    PXOPT_COPY_STR(config->args, where, "-component", "component", "==");
     978
     979    // start a transaction eraly so it will contain any row level locks
     980    if (!psDBTransaction(config->dbh)) {
     981        psError(PS_ERR_UNKNOWN, false, "database error");
     982        return false;
     983    }
     984
     985    psString query = pxDataGet("pstamptool_getdependent.sql");
    918986    if (!query) {
    919         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    920         return false;
    921     }
     987        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     988        return false;
     989    }
     990    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     991    if (!no_create) {
     992        // This will lock the row until the transaction is committed
     993        psStringAppend(&query, " AND %s FOR UPDATE", whereClause);
     994    } else {
     995        psStringAppend(&query, " AND %s", whereClause);
     996    }
     997    psFree(whereClause);
     998    psFree(where);
     999
    9221000    if (!p_psDBRunQuery(config->dbh, query)) {
    9231001        psError(PS_ERR_UNKNOWN, false, "database error");
     
    9371015        if (!dep_id) {
    9381016            psError(PS_ERR_UNKNOWN, false, "database error");
     1017            psFree(output);
    9391018            return false;
    9401019        }
    9411020        printf("%" PRId64 "\n", dep_id);
     1021        psFree(output);
     1022        if (!psDBRollback(config->dbh)) {
     1023            psError(PS_ERR_UNKNOWN, false, "database error");
     1024        }
    9421025        return true;
    9431026    }
    9441027    if (no_create) {
     1028        if (!psDBRollback(config->dbh)) {
     1029            psError(PS_ERR_UNKNOWN, false, "database error");
     1030            return false;
     1031        }
    9451032        return true;
    9461033    }
    9471034    // no existing dependent that matches, insert one
     1035    // Since we have multiple processes running jobs we have a
     1036    // race condition here so that's why we need to lock the table
    9481037
    9491038    if (!pstampDependentInsert(
     
    9531042        stage,
    9541043        stage_id,
     1044        component,
    9551045        imagedb,
    9561046        rlabel,
    957         no_magic
     1047        need_magic,
     1048        0               // fault
    9581049        )) {
     1050        if (!psDBRollback(config->dbh)) {
     1051            psError(PS_ERR_UNKNOWN, false, "database error");
     1052        }
    9591053        psError(PS_ERR_UNKNOWN, false, "failed to insert pstampDependent");
    9601054        return false;
    9611055    }
    9621056
     1057    // if we try and get this after commit zero is returned
    9631058    psS64 dep_id = psDBLastInsertID(config->dbh);
     1059    if (!dep_id) {
     1060        psError(PS_ERR_UNKNOWN, false, "psDBLastInsertID returned NULL");
     1061        if (!psDBRollback(config->dbh)) {
     1062            psError(PS_ERR_UNKNOWN, false, "database error");
     1063        }
     1064        return false;
     1065    }
     1066
     1067    if (!psDBCommit(config->dbh)) {
     1068        // rollback
     1069        if (!psDBRollback(config->dbh)) {
     1070            psError(PS_ERR_UNKNOWN, false, "database error");
     1071        }
     1072        psError(PS_ERR_UNKNOWN, false, "database error");
     1073        return false;
     1074    }
    9641075
    9651076    printf("%" PRId64 "\n", dep_id);
     
    9731084
    9741085    psMetadata *where = psMetadataAlloc();
     1086    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     1087    PXOPT_COPY_STR(config->args, where, "-imagedb", "imagedb", "==");
     1088    PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
     1089    PXOPT_COPY_STR(config->args, where, "-rlabel", "rlabel", "==");
     1090    pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "==");
    9751091
    9761092    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     
    9791095    psString query = pxDataGet("pstamptool_pendingdependent.sql");
    9801096    if (!query) {
    981         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1097        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    9821098        return false;
    9831099    }
    9841100
    9851101    if (psListLength(where->list)) {
    986         psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampDependent");
     1102        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    9871103        psStringAppend(&query, " AND %s", whereClause);
    9881104        psFree(whereClause);
     
    10311147
    10321148    PXOPT_LOOKUP_S64(dep_id,    config->args, "-dep_id", true, false);
    1033     PXOPT_LOOKUP_STR(state,     config->args, "-set_state",  true, false);
    1034 
    1035     char *query ="UPDATE pstampDependent"
    1036         " SET state = '%s'"
    1037         " WHERE dep_id = %" PRId64;
    1038    
    1039     if (!p_psDBRunQueryF(config->dbh, query, state, dep_id)) {
     1149    PXOPT_LOOKUP_STR(state,     config->args, "-set_state",  false, false);
     1150    PXOPT_LOOKUP_S16(fault,     config->args, "-fault",  false, false);
     1151
     1152    if (!fault && !state) {
     1153        psError(PS_ERR_UNKNOWN, true, "at least one of -set_state or fault is required");
     1154        return false;
     1155    }
     1156    psString query = psStringCopy("UPDATE pstampDependent SET");
     1157    bool needComma = false;
     1158    if (state) {
     1159        psStringAppend(&query, " state = '%s'", state);
     1160        needComma = true;
     1161    }
     1162    if (fault) {
     1163        psStringAppend(&query, "%s fault = %d", needComma ? ", " : "", fault);
     1164        needComma = true;
     1165    }
     1166    psStringAppend(&query, " WHERE dep_id = %" PRId64, dep_id);
     1167
     1168    if (!p_psDBRunQuery(config->dbh, query)) {
    10401169        psError(PS_ERR_UNKNOWN, false, "database error");
    10411170        psFree(query);
     
    10451174    psU64 affected = psDBAffectedRows(config->dbh);
    10461175    if (affected != 1) {
    1047         psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 
     1176        psError(PS_ERR_UNKNOWN, false, "should have affected one row but %"
    10481177                                        PRIu64 " rows were modified", affected);
    10491178        return false;
     
    10521181    return true;
    10531182}
     1183static bool revertdependentMode(pxConfig *config)
     1184{
     1185    PS_ASSERT_PTR_NON_NULL(config, false);
     1186
     1187    psMetadata *where = psMetadataAlloc();
     1188    PXOPT_COPY_S64(config->args, where, "-fault", "pstampDependent.fault", "==");
     1189    PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "==");
     1190    pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "==");
     1191
     1192    if (!psListLength(where->list)) {
     1193        psFree(where);
     1194        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     1195        return false;
     1196    }
     1197    psString query = pxDataGet("pstamptool_revertdependent.sql");
     1198    if (!query) {
     1199        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1200        return false;
     1201    }
     1202
     1203    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1204    psStringAppend(&query, " AND %s", whereClause);
     1205    psFree(whereClause);
     1206    psFree(where);
     1207
     1208    if (!p_psDBRunQuery(config->dbh, query)) {
     1209        psError(PS_ERR_UNKNOWN, false, "database error");
     1210        psFree(query);
     1211        return false;
     1212    }
     1213
     1214    return true;
     1215}
Note: See TracChangeset for help on using the changeset viewer.