IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 18, 2010, 12:49:05 PM (16 years ago)
Author:
eugene
Message:

merging changes from trunk into branches/pap

Location:
branches/pap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/ippTools/src/pstamptool.c

    r27282 r28003  
    4040static bool updatereqMode(pxConfig *config);
    4141static bool revertreqMode(pxConfig *config);
     42static bool pendingcleanupMode(pxConfig *config);
    4243static bool addjobMode(pxConfig *config);
    4344static bool listjobMode(pxConfig *config);
     
    5152static bool pendingdependentMode(pxConfig *config);
    5253static bool updatedependentMode(pxConfig *config);
     54static bool revertdependentMode(pxConfig *config);
    5355
    5456# define MODECASE(caseName, func) \
     
    8082        MODECASE(PSTAMPTOOL_MODE_UPDATEREQ, updatereqMode);
    8183        MODECASE(PSTAMPTOOL_MODE_REVERTREQ, revertreqMode);
     84        MODECASE(PSTAMPTOOL_MODE_PENDINGCLEANUP, pendingcleanupMode);
    8285        MODECASE(PSTAMPTOOL_MODE_ADDJOB, addjobMode);
    8386        MODECASE(PSTAMPTOOL_MODE_LISTJOB, listjobMode);
     
    9194        MODECASE(PSTAMPTOOL_MODE_PENDINGDEPENDENT, pendingdependentMode);
    9295        MODECASE(PSTAMPTOOL_MODE_UPDATEDEPENDENT, updatedependentMode);
     96        MODECASE(PSTAMPTOOL_MODE_REVERTDEPENDENT, revertdependentMode);
    9397        default:
    9498            psAbort("invalid option (this should not happen)");
     
    263267        NULL,   // outProduct
    264268        uri,
     269        NULL,   // outdir
    265270        0       // fault
    266271        )) {
     
    299304    }
    300305    psFree(where);
     306
     307    psStringAppend(&query, " ORDER BY priority DESC, req_id");
    301308
    302309    // treat limit == 0 as "no limit"
     
    337344}
    338345
    339 static bool listreqMode(pxConfig *config)
     346static bool pendingcleanupMode(pxConfig *config)
    340347{
    341348    PS_ASSERT_PTR_NON_NULL(config, false);
     
    343350    psMetadata *where = psMetadataAlloc();
    344351    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
    345     PXOPT_COPY_S64(config->args, where, "-not_req_id", "req_id", "!=");
    346     PXOPT_COPY_STR(config->args, where, "-name", "name", "==");
    347 
    348     PXOPT_LOOKUP_U64(limit,   config->args, "-limit",  false, false);
     352    pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE");
     353
     354    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    349355    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    350356
    351     if (!psListLength(where->list)) {
    352         psError(PS_ERR_UNKNOWN, true, "-req_id or -name must be supplied");
    353         return false;
    354     }
    355 
    356     psString query = psStringCopy("SELECT * from pstampRequest");
    357 
    358     psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    359     psStringAppend(&query, " WHERE %s", whereClause);
    360     psFree(whereClause);
    361     psFree(where);
     357    psString query = pxDataGet("pstamptool_pendingcleanup.sql");
     358    if (!query) {
     359        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     360        return false;
     361    }
     362
     363    if (psListLength(where->list)) {
     364        psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampRequest");
     365        psStringAppend(&query, " AND %s", whereClause);
     366        psFree(whereClause);
     367    }
     368    psFree(where);
     369
     370    psStringAppend(&query, " ORDER BY priority DESC, req_id");
    362371
    363372    // treat limit == 0 as "no limit"
     
    381390    }
    382391    if (!psArrayLength(output)) {
    383         psTrace("pstamptool", PS_LOG_INFO, "request not found");
    384         // This causes main to exit with PS_EXIT_DATA_ERROR which the script is looking for
    385         psError(PXTOOLS_ERR_CONFIG, true, "request not found");
    386         psFree(output);
    387         // we return false so that the caller can determine that a request does not exist
    388         return false;
     392        psTrace("pstamptool", PS_LOG_INFO, "no rows found");
     393        psFree(output);
     394        return true;
    389395    }
    390396
     
    401407}
    402408
    403 static bool completedreqMode(pxConfig *config)
    404 {
    405     PS_ASSERT_PTR_NON_NULL(config, false);
    406 
    407     psMetadata *where = psMetadataAlloc();
    408     pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE");
    409 
    410     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     409static bool listreqMode(pxConfig *config)
     410{
     411    PS_ASSERT_PTR_NON_NULL(config, false);
     412
     413    psMetadata *where = psMetadataAlloc();
     414    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
     415    PXOPT_COPY_S64(config->args, where, "-not_req_id", "req_id", "!=");
     416    PXOPT_COPY_STR(config->args, where, "-name", "name", "==");
     417
     418    PXOPT_LOOKUP_U64(limit,   config->args, "-limit",  false, false);
    411419    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    412420
    413     psString query = pxDataGet("pstamptool_completedreq.sql");
    414 
    415     if (psListLength(where->list)) {
    416         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    417         psStringAppend(&query, " AND %s", whereClause);
    418         psFree(whereClause);
    419     }
     421    if (!psListLength(where->list)) {
     422        psError(PS_ERR_UNKNOWN, true, "-req_id or -name must be supplied");
     423        return false;
     424    }
     425
     426    psString query = psStringCopy("SELECT * from pstampRequest");
     427
     428    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     429    psStringAppend(&query, " WHERE %s", whereClause);
     430    psFree(whereClause);
    420431    psFree(where);
    421432
     
    432443        return false;
    433444    }
     445    psFree(query);
    434446
    435447    psArray *output = p_psDBFetchResult(config->dbh);
     
    438450        return false;
    439451    }
    440 
    441452    if (!psArrayLength(output)) {
    442         psTrace("pstamptool", PS_LOG_INFO, "no rows found");
    443         psFree(output);
    444         return true;
     453        psTrace("pstamptool", PS_LOG_INFO, "request not found");
     454        // This causes main to exit with PS_EXIT_DATA_ERROR which the script is looking for
     455        psError(PXTOOLS_ERR_CONFIG, true, "request not found");
     456        psFree(output);
     457        // we return false so that the caller can determine that a request does not exist
     458        return false;
    445459    }
    446460
     
    457471}
    458472
     473static bool completedreqMode(pxConfig *config)
     474{
     475    PS_ASSERT_PTR_NON_NULL(config, false);
     476
     477    psMetadata *where = psMetadataAlloc();
     478    pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE");
     479
     480    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     481    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     482
     483    psString query = pxDataGet("pstamptool_completedreq.sql");
     484
     485    if (psListLength(where->list)) {
     486        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     487        psStringAppend(&query, " AND %s", whereClause);
     488        psFree(whereClause);
     489    }
     490    psFree(where);
     491
     492    psStringAppend(&query, " ORDER BY priority DESC, req_id");
     493
     494    // treat limit == 0 as "no limit"
     495    if (limit) {
     496        psString limitString = psDBGenerateLimitSQL(limit);
     497        psStringAppend(&query, " %s", limitString);
     498        psFree(limitString);
     499    }
     500
     501    if (!p_psDBRunQuery(config->dbh, query)) {
     502        psError(PS_ERR_UNKNOWN, false, "database error");
     503        psFree(query);
     504        return false;
     505    }
     506
     507    psArray *output = p_psDBFetchResult(config->dbh);
     508    if (!output) {
     509        psError(PS_ERR_UNKNOWN, false, "database error");
     510        return false;
     511    }
     512
     513    if (!psArrayLength(output)) {
     514        psTrace("pstamptool", PS_LOG_INFO, "no rows found");
     515        psFree(output);
     516        return true;
     517    }
     518
     519    // negative simple so the default is true
     520    if (!ippdbPrintMetadatas(stdout, output, "pstampRequest", !simple)) {
     521        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     522        psFree(output);
     523        return false;
     524    }
     525
     526    psFree(output);
     527
     528    return true;
     529}
     530
    459531static bool updatereqMode(pxConfig *config)
    460532{
    461533    PS_ASSERT_PTR_NON_NULL(config, false);
    462534
    463     PXOPT_LOOKUP_S64(req_id,     config->args, "-req_id",     true, false);
    464     PXOPT_LOOKUP_STR(state,      config->args, "-state",      false, false);
    465     PXOPT_LOOKUP_STR(outProduct, config->args, "-outProduct", false, false);
    466     PXOPT_LOOKUP_STR(fault,      config->args, "-fault",      false, false);
    467     PXOPT_LOOKUP_STR(uri,        config->args, "-uri",        false, false);
    468     PXOPT_LOOKUP_STR(name,       config->args, "-name",       false, false);
    469     PXOPT_LOOKUP_STR(reqType,    config->args, "-reqType",    false, false);
    470 
    471     psString query = NULL;
    472     psStringAppend(&query, "UPDATE pstampRequest SET");
    473 
     535    // PXOPT_LOOKUP_S64(req_id,     config->args, "-req_id",   true, false);
     536    PXOPT_LOOKUP_STR(state,      config->args, "-set_state",      false, false);
     537    PXOPT_LOOKUP_STR(label,      config->args, "-set_label",      false, false);
     538    PXOPT_LOOKUP_STR(outProduct, config->args, "-set_outProduct", false, false);
     539    PXOPT_LOOKUP_S16(fault,      config->args, "-set_fault",          false, false);
     540    PXOPT_LOOKUP_STR(uri,        config->args, "-set_uri",        false, false);
     541    PXOPT_LOOKUP_STR(outdir,     config->args, "-set_outdir",        false, false);
     542    PXOPT_LOOKUP_STR(name,       config->args, "-set_name",       false, false);
     543    PXOPT_LOOKUP_STR(reqType,    config->args, "-set_reqType",    false, false);
     544    PXOPT_LOOKUP_BOOL(clearfault,config->args, "-clearfault",    false);
     545
     546    psMetadata *where = psMetadataAlloc();
     547    PXOPT_COPY_S64(config->args, where, "-req_id",     "req_id", "==");
     548    PXOPT_COPY_S64(config->args, where, "-req_id_max", "req_id", "<=");
     549    PXOPT_COPY_S32(config->args, where, "-fault",      "fault", "==");
     550    PXOPT_COPY_STR(config->args, where, "-state",      "state", "==");
     551    pxAddLabelSearchArgs(config, where, "-label",      "pstampRequest.label", "LIKE");
     552    if (!psListLength(where->list)) {
     553        psFree(where);
     554        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     555        return false;
     556    }
     557
     558    psString query = psStringCopy("UPDATE pstampRequest SET");
     559
     560    psString stateCheck = NULL;
    474561    char c = ' ';
    475562    if (state) {
    476563        psStringAppend(&query, "%c state = '%s'", c, state);
    477564        c = ',';
     565        if (!strcmp(state, "goto_cleaned")) {
     566            psStringAppend(&stateCheck, " AND state != 'cleaned'");
     567        }
     568    }
     569    if (label) {
     570        psStringAppend(&query, "%c label = '%s'", c, label);
     571        c = ',';
    478572    }
    479573    if (outProduct) {
     
    481575        c = ',';
    482576    }
    483     if (fault) {
    484         psStringAppend(&query, "%c fault = %s", c, fault);
     577    if (outdir) {
     578        psStringAppend(&query, "%c outdir = '%s'", c, outdir);
     579        c = ',';
     580    }
     581    if (clearfault) {
     582        if (fault) {
     583            psError(PXTOOLS_ERR_CONFIG, true, "only one of -fault and -clearfault is allowed");
     584            return false;
     585        }
     586        psStringAppend(&query, "%c fault = 0", c);
     587        c = ',';
     588    } else if (fault) {
     589        psStringAppend(&query, "%c fault = %d", c, fault);
    485590        c = ',';
    486591    }
     
    497602        c = ',';
    498603    }
    499     if (!state && !outProduct && !fault && !uri && !name && !reqType) {
    500         psError(PS_ERR_UNKNOWN, true, "at least one of state, outProduct, fault, uri, name, and reqType must be specified");
    501         return false;
    502     }
    503 
    504     psStringAppend(&query, " WHERE req_id = %" PRId64, req_id);
     604    if (c != ',') {
     605        psError(PS_ERR_UNKNOWN, true, "at least one set option is required");
     606        return false;
     607    }
     608
     609    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     610    psStringAppend(&query, "\nWHERE %s", whereClause);
     611    psFree(whereClause);
     612    psFree(where);
     613
     614    if (stateCheck) {
     615        psStringAppend(&query, "%s", stateCheck);
     616    }
    505617
    506618    if (!p_psDBRunQuery(config->dbh, query)) {
     
    510622    }
    511623
    512     psU64 affected = psDBAffectedRows(config->dbh);
    513     // note zero is not an error
    514     if (affected > 1) {
    515         psError(PS_ERR_UNKNOWN, false, "should have affected one row but %"
    516                                         PRIu64 " rows were modified", affected);
    517         return false;
    518     }
     624    // psU64 affected = psDBAffectedRows(config->dbh);
     625    // psLogMsg("pstamptool", PS_LOG_INFO, "Updated %" PRIu64 " pstampRequests", affected);
    519626
    520627    return true;
     
    528635
    529636    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
    530     PXOPT_COPY_S64(config->args, where, "-fault", "req_id", "==");
     637    PXOPT_COPY_S64(config->args, where, "-fault", "fault", "==");
    531638    PXOPT_COPY_STR(config->args, where, "-state", "pstampRequest.state", "==");
    532639    pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "LIKE");
     
    703810    PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "==");
    704811    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
    705     pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE");
     812    pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "LIKE");
    706813
    707814    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     
    722829    psFree(where);
    723830
     831    psStringAppend(&query, " ORDER BY priority DESC, req_id");
     832
    724833    // treat limit == 0 as "no limit"
    725834    if (limit) {
     
    763872    PS_ASSERT_PTR_NON_NULL(config, false);
    764873
    765     PXOPT_LOOKUP_S64(job_id,    config->args, "-job_id", true, false);
    766     PXOPT_LOOKUP_STR(state,     config->args, "-state",  true, false);
    767     PXOPT_LOOKUP_STR(fault,     config->args, "-fault",  false, false);
    768 
    769     psString faultStr = NULL;
    770     if (!fault) {
    771         faultStr = psStringCopy("");
    772     } else {
    773         psStringAppend(&faultStr, ", fault = '%s'", fault);
    774     }
    775 
    776     char *query ="UPDATE pstampJob"
    777         " SET state = '%s' %s"
    778         " WHERE job_id = %" PRId64;
    779 
    780     if (!p_psDBRunQueryF(config->dbh, query, state, faultStr, job_id)) {
     874    PXOPT_LOOKUP_S64(job_id,    config->args, "-job_id", false, false);
     875    PXOPT_LOOKUP_S64(dep_id,    config->args, "-dep_id", false, false);
     876
     877    if (!job_id && !dep_id) {
     878        psError(PS_ERR_UNKNOWN, true, "at least -job_id or -dep_id is required");
     879        return false;
     880    }
     881
     882    PXOPT_LOOKUP_STR(state,     config->args, "-set_state",  false, false);
     883    PXOPT_LOOKUP_S32(fault,     config->args, "-set_fault",  false, false);
     884   
     885    if (!state && !fault) {
     886        psError(PS_ERR_UNKNOWN, true, "at least one of -set_state and -set_fault is required");
     887        return false;
     888    }
     889
     890    psMetadata *where = psMetadataAlloc();
     891
     892    PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "==");
     893    PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "==");
     894
     895    psString query = pxDataGet("pstamptool_updatejob.sql");
     896
     897    char c = ' ';
     898    if (state) {
     899        psStringAppend(&query, "\n %c pstampJob.state = '%s'", c, state);
     900        c = ',';
     901    }
     902    if (fault) {
     903        psStringAppend(&query, "\n %c pstampJob.fault = %d", c, fault);
     904        c = ',';
     905    }
     906   
     907    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     908    psStringAppend(&query, " WHERE %s", whereClause);
     909    psFree(whereClause);
     910    psFree(where);
     911
     912    if (!p_psDBRunQuery(config->dbh, query)) {
    781913        psError(PS_ERR_UNKNOWN, false, "database error");
    782914        psFree(query);
    783915        return false;
    784916    }
    785     psFree(faultStr);
     917    psFree(query);
    786918
    787919    psU64 affected = psDBAffectedRows(config->dbh);
    788     if (affected != 1) {
    789         psError(PS_ERR_UNKNOWN, false, "should have affected one row but %"
    790                                         PRIu64 " rows were modified", affected);
    791         return false;
    792     }
     920    psLogMsg("pstamptool", PS_LOG_INFO, "Updated %" PRIu64 " pstampJobs", affected);
    793921
    794922    return true;
     
    9521080    PXOPT_LOOKUP_STR(stage,       config->args, "-stage",   true, false);
    9531081    PXOPT_LOOKUP_S64(stage_id,    config->args, "-stage_id", true, false);
     1082    PXOPT_LOOKUP_STR(component,   config->args, "-component",  true, false);
    9541083    PXOPT_LOOKUP_STR(imagedb,     config->args, "-imagedb",  true, false);
    955     PXOPT_LOOKUP_STR(rlabel,      config->args, "-rlabel",  false, false);
    956     PXOPT_LOOKUP_BOOL(no_magic,   config->args, "-no_magic", false);
     1084    PXOPT_LOOKUP_STR(rlabel,      config->args, "-rlabel",  true, false);
     1085    PXOPT_LOOKUP_STR(outdir,      config->args, "-outdir",  true, false);
     1086    PXOPT_LOOKUP_BOOL(need_magic, config->args, "-need_magic", false);
    9571087    PXOPT_LOOKUP_BOOL(no_create,  config->args, "-no_create", false);
    9581088
     
    9611091    PXOPT_COPY_STR(config->args, where, "-imagedb", "imagedb", "==");
    9621092    PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
     1093    PXOPT_COPY_STR(config->args, where, "-component", "component", "==");
    9631094
    9641095    // start a transaction eraly so it will contain any row level locks
     
    9681099    }
    9691100
    970     psString query = pxDataGet("pstamptool_pendingdependent.sql");
     1101    psString query = pxDataGet("pstamptool_getdependent.sql");
    9711102    if (!query) {
    9721103        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    9731104        return false;
    9741105    }
    975     psString whereClause = psDBGenerateWhereSQL(where, "WHERE");
     1106    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    9761107    if (!no_create) {
    9771108        // This will lock the row until the transaction is committed
    978         psStringAppend(&query, " %s FOR UPDATE", whereClause);
     1109        psStringAppend(&query, " AND %s FOR UPDATE", whereClause);
    9791110    } else {
    980         psStringAppend(&query, " %s", whereClause);
     1111        psStringAppend(&query, " AND %s", whereClause);
    9811112    }
    9821113    psFree(whereClause);
     
    10271158        stage,
    10281159        stage_id,
     1160        component,
    10291161        imagedb,
    10301162        rlabel,
    1031         no_magic
     1163        need_magic,
     1164        outdir,
     1165        0               // fault
    10321166        )) {
    10331167        if (!psDBRollback(config->dbh)) {
     
    10381172    }
    10391173
     1174    // if we try and get this after commit zero is returned
     1175    psS64 dep_id = psDBLastInsertID(config->dbh);
     1176    if (!dep_id) {
     1177        psError(PS_ERR_UNKNOWN, false, "psDBLastInsertID returned NULL");
     1178        if (!psDBRollback(config->dbh)) {
     1179            psError(PS_ERR_UNKNOWN, false, "database error");
     1180        }
     1181        return false;
     1182    }
     1183
    10401184    if (!psDBCommit(config->dbh)) {
    10411185        // rollback
     
    10471191    }
    10481192
    1049     psS64 dep_id = psDBLastInsertID(config->dbh);
    10501193    printf("%" PRId64 "\n", dep_id);
    10511194
     
    10581201
    10591202    psMetadata *where = psMetadataAlloc();
     1203    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     1204    PXOPT_COPY_STR(config->args, where, "-imagedb", "imagedb", "==");
     1205    PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
     1206    PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "==");
     1207    PXOPT_COPY_STR(config->args, where, "-rlabel", "rlabel", "==");
     1208    pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "==");
    10601209
    10611210    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     
    10691218
    10701219    if (psListLength(where->list)) {
    1071         psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampDependent");
     1220        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    10721221        psStringAppend(&query, " AND %s", whereClause);
    10731222        psFree(whereClause);
    10741223    }
    10751224    psFree(where);
     1225
     1226    psStringAppend(&query, " ORDER BY priority DESC, req_id");
    10761227
    10771228    // treat limit == 0 as "no limit"
     
    11161267
    11171268    PXOPT_LOOKUP_S64(dep_id,    config->args, "-dep_id", true, false);
    1118     PXOPT_LOOKUP_STR(state,     config->args, "-set_state",  true, false);
    1119 
    1120     char *query ="UPDATE pstampDependent"
    1121         " SET state = '%s'"
    1122         " WHERE dep_id = %" PRId64;
    1123 
    1124     if (!p_psDBRunQueryF(config->dbh, query, state, dep_id)) {
     1269    PXOPT_LOOKUP_STR(state,     config->args, "-set_state",  false, false);
     1270    PXOPT_LOOKUP_S16(fault,     config->args, "-set_fault",  false, false);
     1271
     1272    if (!fault && !state) {
     1273        psError(PS_ERR_UNKNOWN, true, "at least one of -set_state or fault is required");
     1274        return false;
     1275    }
     1276    psString query = psStringCopy("UPDATE pstampDependent SET");
     1277    bool needComma = false;
     1278    if (state) {
     1279        psStringAppend(&query, " state = '%s'", state);
     1280        needComma = true;
     1281    }
     1282    if (fault) {
     1283        psStringAppend(&query, "%s fault = %d", needComma ? ", " : "", fault);
     1284        needComma = true;
     1285    }
     1286    psStringAppend(&query, " WHERE dep_id = %" PRId64, dep_id);
     1287
     1288    if (!p_psDBRunQuery(config->dbh, query)) {
    11251289        psError(PS_ERR_UNKNOWN, false, "database error");
    11261290        psFree(query);
     
    11371301    return true;
    11381302}
     1303static bool revertdependentMode(pxConfig *config)
     1304{
     1305    PS_ASSERT_PTR_NON_NULL(config, false);
     1306
     1307    psMetadata *where = psMetadataAlloc();
     1308    PXOPT_COPY_S64(config->args, where, "-fault", "pstampDependent.fault", "==");
     1309    PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "==");
     1310    pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "==");
     1311
     1312    if (!psListLength(where->list)) {
     1313        psFree(where);
     1314        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     1315        return false;
     1316    }
     1317    psString query = pxDataGet("pstamptool_revertdependent.sql");
     1318    if (!query) {
     1319        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1320        return false;
     1321    }
     1322
     1323    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1324    psStringAppend(&query, " AND %s", whereClause);
     1325    psFree(whereClause);
     1326    psFree(where);
     1327
     1328    if (!p_psDBRunQuery(config->dbh, query)) {
     1329        psError(PS_ERR_UNKNOWN, false, "database error");
     1330        psFree(query);
     1331        return false;
     1332    }
     1333
     1334    return true;
     1335}
Note: See TracChangeset for help on using the changeset viewer.