IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 13, 2008, 11:21:45 AM (18 years ago)
Author:
eugene
Message:

cleanup command-line argument handling; deprecate config.where

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080706/ippTools/src/pstamptool.c

    r18377 r18496  
    100100    PS_ASSERT_PTR_NON_NULL(config, false);
    101101
    102     bool status = false;
    103     psString uri = psMetadataLookupStr(&status, config->args, "-uri");
    104     if (!status) {
    105         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri");
    106         return false;
    107     }
    108     if (!uri) {
    109         psError(PS_ERR_UNKNOWN, true, "-uri is required");
    110         return false;
    111     }
    112     psString outProduct = psMetadataLookupStr(&status, config->args, "-out_product");
    113     if (!status) {
    114         psError(PS_ERR_UNKNOWN, false, "failed to looku value for -out_product");
    115         return false;
    116     }
    117     if (!outProduct) {
    118         psError(PS_ERR_UNKNOWN, true, "-out_product is required");
    119         return false;
    120     }
    121 
    122     psString lastFileset = psMetadataLookupStr(&status, config->args, "-last_fileset");
    123     psString state = psMetadataLookupStr(&status, config->args, "-state");
    124     if (!state) {
    125         state = "enabled";
    126     }
     102    PXOPT_LOOKUP_STR(uri,         config->args, "-uri",           true, false);
     103    PXOPT_LOOKUP_STR(outProduct,  config->args, "-out_product",   true, false);
     104    PXOPT_LOOKUP_STR(lastFileset, config->args, "-last_fileset", false, false);
     105    PXOPT_LOOKUP_STR(state,       config->args, "-state",         false, false);
    127106
    128107    if (!pstampDataStoreInsert(config->dbh,
     
    142121static bool datastoreMode(pxConfig *config)
    143122{
    144     bool status = false;
    145     PS_ASSERT_PTR_NON_NULL(config, false);
    146 
    147     psString ds_id = psMetadataLookupStr(&status, config->args, "-ds_id");
    148     if (!status) {
    149         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ds_id");
    150         return false;
    151     }
    152 
    153     psString query = NULL;
    154     psStringAppend(&query, "SELECT * FROM pstampDataStore");
    155     if (ds_id) {
    156         psStringAppend(&query, " WHERE ds_id = '%s'", ds_id);
    157     }
     123    PS_ASSERT_PTR_NON_NULL(config, false);
     124
     125    psMetadata *where = psMetadataAlloc();
     126    PXOPT_COPY_STR(config->args, where, "-ds_id", "ds_id", "==");
     127
     128    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     129
     130    psString query = pxDataGet("pstamptool_datastore.sql");
     131    if (!query) {
     132        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     133        return false;
     134    }
     135
     136    if (psListLength(where->list)) {
     137        psString whereClause = psDBGenerateWhereSQL(where, NULL);
     138        psStringAppend(&query, " %s", whereClause);
     139        psFree(whereClause);
     140    }
     141    psFree(where);
     142
    158143    if (!p_psDBRunQuery(config->dbh, query)) {
    159144        psError(PS_ERR_UNKNOWN, false, "database error");
     
    170155        psFree(output);
    171156        return true;
    172     }
    173 
    174     bool simple = false;
    175     {
    176         bool status = false;
    177         simple = psMetadataLookupBool(&status, config->args, "-simple");
    178         if (!status) {
    179             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    180             return false;
    181         }
    182157    }
    183158
     
    195170static bool moddatastoreMode(pxConfig *config)
    196171{
    197     bool    status;
    198 
    199     PS_ASSERT_PTR_NON_NULL(config, false);
    200 
    201     psString ds_id = psMetadataLookupStr(&status, config->args, "-ds_id");
    202     if (!status) {
    203         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ds_id");
    204         return false;
    205     }
    206     if (!ds_id) {
    207         psError(PS_ERR_UNKNOWN, true, "-ds_id is required");
    208         return false;
    209     }
    210     psString lastFileset = psMetadataLookupStr(&status, config->args, "-last_fileset");
    211     if (!status) {
    212         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -last_fileset");
    213         return false;
    214     }
    215     psString state = psMetadataLookupStr(&status, config->args, "-state");
    216     if (!status) {
    217         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -state");
    218         return false;
    219     }
     172    PS_ASSERT_PTR_NON_NULL(config, false);
     173
     174    PXOPT_LOOKUP_STR(ds_id,       config->args, "-ds_id",         true, false);
     175    PXOPT_LOOKUP_STR(lastFileset, config->args, "-last_fileset",  false, false);
     176    PXOPT_LOOKUP_STR(state,       config->args, "-state",         false, false);
    220177
    221178    if (!state && !lastFileset) {
     
    224181    }
    225182
    226     char *query = NULL;
     183    char *query = psStringCopy ("UPDATE pstampDataStore SET");
    227184    bool needComma = false;
    228185   
    229     psStringAppend(&query, "UPDATE pstampDataStore SET");
    230 
    231186    if (lastFileset) {
    232187        psStringAppend(&query, " lastFileset = '%s'", lastFileset);
     
    235190
    236191    if (state) {
    237         psStringAppend(&query, "%s state = '%s'", needComma ? "," : " ",
    238             state);
     192        psStringAppend(&query, "%s state = '%s'", needComma ? "," : " ", state);
    239193        needComma = true; // be ready in case we add another field
    240194    }
     
    261215
    262216// Replace $REQ_ID with the value of the request id if present in the outFileset
     217// XXX EAM : rewrite this using psStringSubstitute:
     218// word = psStringAppend (NULL, "%" PRId64, req_id;
     219// converted = psStringSubstitute (outFileset, word, MAGIC_STR);
    263220
    264221static bool
     
    303260static bool addReqMode(pxConfig *config)
    304261{
    305     bool    status;
    306 
    307     PS_ASSERT_PTR_NON_NULL(config, false);
    308 
    309     psString uri = psMetadataLookupStr(&status, config->args, "-uri");
    310     if (!status) {
    311         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri");
    312         return false;
    313     }
    314     if (!uri) {
    315         psError(PS_ERR_UNKNOWN, true, "-uri is required");
    316         return false;
    317     }
    318     psString outFileset = psMetadataLookupStr(&status, config->args, "-out_fileset");
    319     if (!status) {
    320         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -out_fileset");
    321         return false;
    322     }
    323     if (!outFileset) {
    324         psError(PS_ERR_UNKNOWN, true, "-out_fileset is required");
    325         return false;
    326     }
    327 
    328     // Data Store ID is optional
    329     psString ds_id = psMetadataLookupStr(&status, config->args, "-ds_id");
    330     if (!status) {
    331         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ds_id");
    332         return false;
    333     }
    334     if (!ds_id) {
    335         ds_id = "0";
    336     }
     262    PS_ASSERT_PTR_NON_NULL(config, false);
     263
     264    PXOPT_LOOKUP_STR(uri,         config->args, "-uri",           true, false);
     265    PXOPT_LOOKUP_STR(outFileset,  config->args, "-out_fileset",   true, false);
     266    PXOPT_LOOKUP_STR(ds_id,       config->args, "-ds_id",         false, false);
    337267
    338268    char *query ="INSERT INTO pstampRequest"
     
    368298    PS_ASSERT_PTR_NON_NULL(config, false);
    369299
    370     bool status = false;
    371     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
    372     if (!status) {
    373         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
    374         return false;
    375     }
    376 
    377     psString query = psStringCopy(
    378             "SELECT"
    379             " *"
    380             " FROM pstampRequest"
    381             " WHERE state = 'new'"
    382         );
    383 
    384     if (config->where) {
    385         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pstampRequest");
     300    psMetadata *where = psMetadataAlloc();
     301    PXOPT_COPY_STR(config->args, where, "-ds_id", "ds_id", "==");
     302
     303    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     304    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     305
     306    psString query = pxDataGet("pstamptool_pendingreq.sql");
     307    if (!query) {
     308        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     309        return false;
     310    }
     311
     312    if (psListLength(where->list)) {
     313        psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampRequest");
    386314        psStringAppend(&query, " AND %s", whereClause);
    387315        psFree(whereClause);
    388316    }
     317    psFree(where);
    389318
    390319    // treat limit == 0 as "no limit"
     
    413342    }
    414343
    415     bool simple = false;
    416     {
    417         bool status = false;
    418         simple = psMetadataLookupBool(&status, config->args, "-simple");
    419         if (!status) {
    420             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    421             psFree(output);
    422             return false;
    423         }
    424     }
    425 
    426344    // negative simple so the default is true
    427345    if (!ippdbPrintMetadatas(stdout, output, "pstampRequest", !simple)) {
     
    435353    return true;
    436354}
    437 static bool completedReqMode(pxConfig *config)
    438 {
    439     PS_ASSERT_PTR_NON_NULL(config, false);
    440 
    441     bool status = false;
    442     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
    443     if (!status) {
    444         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
    445         return false;
    446     }
    447 
    448     psString query =
    449         "SELECT * FROM pstampRequest WHERE state = 'run' AND "
    450             "(SELECT count(*) FROM pstampJob WHERE pstampJob.req_id = pstampRequest.req_id "
    451             " AND pstampJob.state != 'stop') = 0" ;
     355
     356static bool listReqMode(pxConfig *config)
     357{
     358    PS_ASSERT_PTR_NON_NULL(config, false);
     359
     360    PXOPT_LOOKUP_STR(req_id,  config->args, "-req_id", true, false);
     361    PXOPT_LOOKUP_U64(limit,   config->args, "-limit",  false, false);
     362    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     363
     364    psString query = NULL;
     365    psStringAppend(&query, "SELECT"
     366                   " *"
     367                   " FROM pstampRequest"
     368                   " WHERE req_id = %s", req_id);
    452369
    453370    // treat limit == 0 as "no limit"
     
    463380        return false;
    464381    }
     382    psFree(query);
    465383
    466384    psArray *output = p_psDBFetchResult(config->dbh);
     
    469387        return false;
    470388    }
    471 
    472389    if (!psArrayLength(output)) {
    473390        psTrace("pstamptool", PS_LOG_INFO, "no rows found");
    474391        psFree(output);
    475392        return true;
    476     }
    477 
    478     bool simple = false;
    479     {
    480         bool status = false;
    481         simple = psMetadataLookupBool(&status, config->args, "-simple");
    482         if (!status) {
    483             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    484             psFree(output);
    485             return false;
    486         }
    487393    }
    488394
     
    499405}
    500406
    501 static bool listReqMode(pxConfig *config)
    502 {
    503     PS_ASSERT_PTR_NON_NULL(config, false);
    504 
    505     bool status = false;
    506     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
    507     if (!status) {
    508         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
    509         return false;
    510     }
    511 
    512     psString query = NULL;
    513 
    514     psString req_id = psMetadataLookupStr(&status, config->args, "-req_id");
    515    
    516     if (req_id) {
    517         psStringAppend(&query,
    518                 "SELECT"
    519                 " *"
    520                 " FROM pstampRequest"
    521                 " WHERE req_id = %s", req_id
    522             );
    523     } else {
    524         fprintf(stderr, "req_id must be specified\n");
    525         exit (1);
    526     }
     407static bool completedReqMode(pxConfig *config)
     408{
     409    PS_ASSERT_PTR_NON_NULL(config, false);
     410
     411    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     412    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     413
     414    psString query =
     415        "SELECT * FROM pstampRequest WHERE state = 'run' AND "
     416            "(SELECT count(*) FROM pstampJob WHERE pstampJob.req_id = pstampRequest.req_id "
     417            " AND pstampJob.state != 'stop') = 0" ;
    527418
    528419    // treat limit == 0 as "no limit"
     
    538429        return false;
    539430    }
    540     psFree(query);
    541431
    542432    psArray *output = p_psDBFetchResult(config->dbh);
     
    545435        return false;
    546436    }
     437
    547438    if (!psArrayLength(output)) {
    548439        psTrace("pstamptool", PS_LOG_INFO, "no rows found");
    549440        psFree(output);
    550441        return true;
    551     }
    552 
    553     bool simple = false;
    554     {
    555         bool status = false;
    556         simple = psMetadataLookupBool(&status, config->args, "-simple");
    557         if (!status) {
    558             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    559             psFree(output);
    560             return false;
    561         }
    562442    }
    563443
     
    576456static bool processedReqMode(pxConfig *config)
    577457{
    578     bool    status;
    579 
    580     PS_ASSERT_PTR_NON_NULL(config, false);
    581 
    582     psString req_id = psMetadataLookupStr(&status, config->args, "-req_id");
    583     if (!status) {
    584         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -req_id");
    585         return false;
    586     }
    587     if (!req_id) {
    588         psError(PS_ERR_UNKNOWN, true, "-req_id is required");
    589         return false;
    590     }
    591     psString state = psMetadataLookupStr(&status, config->args, "-state");
    592     if (!status) {
    593         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -state");
    594         return false;
    595     }
    596     if (!state) {
    597         psError(PS_ERR_UNKNOWN, true, "-state is required");
    598         return false;
    599     }
     458    PS_ASSERT_PTR_NON_NULL(config, false);
     459
     460    PXOPT_LOOKUP_STR(req_id, config->args, "-req_id", true, false);
     461    PXOPT_LOOKUP_STR(state,  config->args, "-state",  true, false);
    600462
    601463    // XXX: check state for a legal value
     
    620482    return true;
    621483}
     484
    622485static bool addJobMode(pxConfig *config)
    623486{
    624     bool    status;
    625487    bool    stampJob = false;
    626 
    627     PS_ASSERT_PTR_NON_NULL(config, false);
    628 
    629     psString job_type = psMetadataLookupStr(&status, config->args, "-job_type");
    630     if (!status) {
    631         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -job_type");
    632         return false;
    633     }
    634     if (job_type) {
    635         if (!strcmp(job_type, "get_image") || !strcmp(job_type, "detect_query")) {
    636             stampJob = false;
    637         } else if (!strcmp(job_type, "stamp")) {
    638             stampJob = true;
    639         } else {
    640             psError(PS_ERR_UNKNOWN, false, "unknown value for -job_type: %s", job_type);
    641             return false;
    642         }
     488    char   *query = NULL;
     489
     490    PS_ASSERT_PTR_NON_NULL(config, false);
     491
     492    PXOPT_LOOKUP_STR(uri,         config->args, "-uri",        true, false);
     493    PXOPT_LOOKUP_STR(req_id,      config->args, "-req_id",     true, false);
     494    PXOPT_LOOKUP_STR(job_type,    config->args, "-job_type",   false, false);
     495    PXOPT_LOOKUP_STR(outputBase,  config->args, "-outputBase", true,  false);
     496    PXOPT_LOOKUP_STR(argString,   config->args, "-args",       true,  false);
     497    PXOPT_LOOKUP_STR(stateString, config->args, "-state",      false, false);
     498    PXOPT_LOOKUP_STR(result,      config->args, "-result",     false, false);
     499
     500    if (!strcmp(job_type, "get_image") || !strcmp(job_type, "detect_query")) {
     501        stampJob = false;
     502    } else if (!strcmp(job_type, "stamp")) {
     503        stampJob = true;
    643504    } else {
    644         job_type = "stamp";
    645         stampJob = true;
    646     }
    647 
    648     psString uri = psMetadataLookupStr(&status, config->args, "-uri");
    649     if (!status) {
    650         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri");
    651         return false;
    652     }
    653     if (!uri) {
    654         psError(PS_ERR_UNKNOWN, true, "-uri is required");
    655         return false;
    656     }
    657 
    658     psString req_id = psMetadataLookupStr(&status, config->args, "-req_id");
    659     if (!status) {
    660         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -req_id");
    661         return false;
    662     }
    663     if (!req_id) {
    664         psError(PS_ERR_UNKNOWN, true, "-req_id is required");
    665         return false;
    666     }
    667 
    668     psString outputBase = psMetadataLookupStr(&status, config->args, "-outputBase");
    669     if (!status) {
    670         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -outputBase");
    671         return false;
    672     }
    673     if (!outputBase) {
    674         psError(PS_ERR_UNKNOWN, true, "-outputBase is required");
    675         return false;
    676     }
    677 
    678     psString argString = psMetadataLookupStr(&status, config->args, "-args");
    679     if (!status) {
    680         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -args");
    681         return false;
    682     }
    683     if (!argString) {
    684         if (stampJob) {
    685             psError(PS_ERR_UNKNOWN, true, "-args is required");
    686             return false;
    687         }
    688     }
    689 
    690     psString stateString = psMetadataLookupStr(&status, config->args, "-state");
    691     if (!status) {
    692         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -state");
    693         return false;
    694     }
    695     if (!stateString) {
    696         stateString = "run";
    697     }
    698     psString result = psMetadataLookupStr(&status, config->args, "-result");
    699     if (!status) {
    700         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -result");
    701         return false;
    702     }
    703     if (!result) {
    704         result = "0";
    705     }
    706 
    707     char *query;
     505        psError(PS_ERR_UNKNOWN, false, "unknown value for -job_type: %s", job_type);
     506        return false;
     507    }
    708508   
    709509    if (stampJob) {
    710         query ="INSERT INTO pstampJob"
    711                  " (req_id, state, jobType, uri, outputBase, result, args)"
    712                  " VALUES( %s, '%s', '%s', '%s', '%s', %s, '%s')";
     510        query = pxDataGet("pstamptool_addjob_stampjob.sql");
    713511    } else {
    714         query ="INSERT INTO pstampJob"
    715                  " (req_id, state, jobType, uri, outputBase, result)"
    716                  " VALUES( %s, '%s', '%s', '%s', '%s', %s)";
     512        query = pxDataGet("pstamptool_addjob_otherjob.sql");
     513    }
     514    if (!query) {
     515        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     516        return false;
    717517    }
    718518
     
    740540    PS_ASSERT_PTR_NON_NULL(config, false);
    741541
    742     bool status = false;
    743     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
    744     if (!status) {
    745         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
    746         return false;
    747     }
     542    PXOPT_LOOKUP_STR(req_id, config->args, "-req_id", false, false);
     543    PXOPT_LOOKUP_STR(job_id, config->args, "-job_id", false, false);
     544
     545    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     546    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    748547
    749548    psString query = NULL;
    750549
    751     psString req_id = psMetadataLookupStr(&status, config->args, "-req_id");
    752     psString job_id = psMetadataLookupStr(&status, config->args, "-job_id");
    753    
     550    if (!req_id && !job_id) {
     551        fprintf(stderr, "either req_id or job_id must be specified\n");
     552        exit (1);
     553    }
     554
    754555    if (req_id) {
    755556        psStringAppend(&query,
     
    759560                " WHERE req_id = %s", req_id
    760561            );
    761     } else if (job_id) {
     562    } else {
    762563        psStringAppend(&query,
    763564                "SELECT"
     
    766567                " WHERE job_id = %s", job_id
    767568            );
    768     } else {
    769         fprintf(stderr, "either req_id or job_id must be specified\n");
    770         exit (1);
    771     }
     569    }
    772570
    773571    // treat limit == 0 as "no limit"
     
    796594    }
    797595
    798     bool simple = false;
    799     {
    800         bool status = false;
    801         simple = psMetadataLookupBool(&status, config->args, "-simple");
    802         if (!status) {
    803             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    804             psFree(output);
    805             return false;
    806         }
    807     }
    808 
    809596    // negative simple so the default is true
    810597    if (!ippdbPrintMetadatas(stdout, output, "pstampJob", !simple)) {
     
    823610    PS_ASSERT_PTR_NON_NULL(config, false);
    824611
    825     bool status = false;
    826     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
    827     if (!status) {
    828         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
    829         return false;
    830     }
    831 
    832     psString query = psStringCopy(
    833             "SELECT"
    834             " *"
    835             " FROM pstampJob"
    836             " WHERE state = 'run'"
    837         );
    838 
    839     if (config->where) {
    840         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pstampJob");
     612    psMetadata *where = psMetadataAlloc();
     613    PXOPT_COPY_S64(config->args, where, "-cam_id", "cam_id", "==");
     614
     615    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     616    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     617
     618    psString query = pxDataGet("pstamptool_pendingjob.sql");
     619    if (!query) {
     620        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     621        return false;
     622    }
     623
     624    // use psDBGenerateWhereSQL because the SQL yields an intermediate table
     625    if (psListLength(where->list)) {
     626        psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampJob");
    841627        psStringAppend(&query, " AND %s", whereClause);
    842628        psFree(whereClause);
    843629    }
     630    psFree(where);
    844631
    845632    // treat limit == 0 as "no limit"
     
    868655    }
    869656
    870     bool simple = false;
    871     {
    872         bool status = false;
    873         simple = psMetadataLookupBool(&status, config->args, "-simple");
    874         if (!status) {
    875             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    876             psFree(output);
    877             return false;
    878         }
    879     }
    880 
    881657    // negative simple so the default is true
    882658    if (!ippdbPrintMetadatas(stdout, output, "pstampJob", !simple)) {
     
    894670{
    895671    bool    status;
    896 
    897     PS_ASSERT_PTR_NON_NULL(config, false);
    898 
    899     psString job_id = psMetadataLookupStr(&status, config->args, "-job_id");
     672    char *query = NULL;
     673
     674    PS_ASSERT_PTR_NON_NULL(config, false);
     675
     676    PXOPT_LOOKUP_STR(job_id,    config->args, "-job_id", true, false);
     677    PXOPT_LOOKUP_STR(state,     config->args, "-state",  true, false);
     678    PXOPT_LOOKUP_STR(jobResult, config->args, "-result", false, false);
     679    // XXX: check state for a legal value
     680
     681    if (jobResult) {
     682        query = psStringCopy ("UPDATE pstampJob"
     683                              " SET state = '%s', result = '%s'"
     684                              " WHERE job_id = '%s'");
     685        status = p_psDBRunQuery(config->dbh, query, state, jobResult, job_id);
     686    } else {
     687        query = psStringCopy ("UPDATE pstampJob"
     688                              " SET state = '%s'"
     689                              " WHERE job_id = '%s'");
     690        status = p_psDBRunQuery(config->dbh, query, state, job_id);
     691    }
     692
    900693    if (!status) {
    901         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -job_id");
    902         return false;
    903     }
    904     if (!job_id) {
    905         psError(PS_ERR_UNKNOWN, true, "-job_id is required");
    906         return false;
    907     }
    908     psString state = psMetadataLookupStr(&status, config->args, "-state");
    909     if (!status) {
    910         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -state");
    911         return false;
    912     }
    913     if (!state) {
    914         psError(PS_ERR_UNKNOWN, true, "-state is required");
    915         return false;
    916     }
    917     psString jobResult = psMetadataLookupStr(&status, config->args, "-result");
    918     if (!status) {
    919         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -result");
    920         return false;
    921     }
    922 
    923     psString resultStr = NULL;
    924     if (!jobResult) {
    925         resultStr = psStringCopy("");
    926     } else {
    927         psStringAppend(&resultStr, ", result = '%s'", jobResult);
    928     }
    929        
    930 
    931     // XXX: check state for a legal value
    932 
    933     char *query ="UPDATE pstampJob"
    934                  " SET state = '%s' %s"
    935                  " WHERE job_id = '%s'";
    936 
    937     if (!p_psDBRunQuery(config->dbh, query, state, resultStr, job_id)) {
    938694        psError(PS_ERR_UNKNOWN, false, "database error");
    939695        psFree(query);
    940696        return false;
    941697    }
    942     psFree(resultStr);
    943698
    944699    psU64 affected = psDBAffectedRows(config->dbh);
Note: See TracChangeset for help on using the changeset viewer.