IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 15, 2008, 10:30:59 AM (18 years ago)
Author:
eugene
Message:

completely deprecate config->where; make all command-line handling consistent; move nearly all sql into share/*.sql; ensure consistency between args supplied and used

File:
1 edited

Legend:

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

    r18336 r18561  
    1818 */
    1919
    20 #ifdef HAVB_CONFIG_H
    21 #include <config.h>
    22 #endif
    23 
    24 #include <stdio.h>
    25 #include <string.h>
    26 #include <stdlib.h>
    27 #include <stdint.h>
    28 #include <inttypes.h>
    29 
    30 #include <ippdb.h>
    31 
    32 #include "pxtools.h"
    3320#include "dettool.h"
    3421
     
    3724    PS_ASSERT_PTR_NON_NULL(config, false);
    3825
    39     bool status     = false;
    40     psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
    41     if (!status) {
    42         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
    43         return false;
    44     }
    45     if (!det_id) {
    46         psError(PS_ERR_UNKNOWN, true, "-det_id is required");
    47         return false;
    48     }
    49 
    50     psArray *runs = detRunSelectRowObjects(config->dbh, config->where, 1);
     26    PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required
     27    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); // optional
     28
     29    // build the needed where
     30    psMetadata *where = psMetadataAlloc();
     31    psMetadataAddS64(where, PS_LIST_TAIL, "det_id", 0, "==", (psS64)atoll(det_id));
     32    psArray *runs = detRunSelectRowObjects(config->dbh, where, 1);
     33    psFree (where);
     34
    5135    if (!psArrayLength(runs)) {
    5236        psError(PS_ERR_UNKNOWN, false, "database error");
     
    10387    }
    10488
    105     psArray *detRuns = NULL;
    106     {
    107         psMetadata *where = psMetadataAlloc();
    108         psMetadataAddS64(where, PS_LIST_TAIL, "det_id", 0, "==", new_det_id);
    109         detRuns = psDBSelectRows(config->dbh, "detRun", where, 0);
    110         psFree(where);
    111     }
     89    psMetadata *where_new = psMetadataAlloc();
     90    psMetadataAddS64(where, PS_LIST_TAIL, "det_id", 0, "==", new_det_id);
     91    psArray *detRuns = psDBSelectRows(config->dbh, "detRun", where_new, 0);
     92    psFree(where_new);
     93
    11294    if (!detRuns) {
    11395        psError(PS_ERR_UNKNOWN, false, "can't find the detRun we just created");
     
    118100        psAbort("found more then one detRun matching det_id %" PRId64 "(this should not happen)", new_det_id);
    119101        return false;
    120     }
    121 
    122     bool simple = false;
    123     {
    124         bool status = false;
    125         simple = psMetadataLookupBool(&status, config->args, "-simple");
    126         if (!status) {
    127             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    128             return false;
    129         }
    130102    }
    131103
     
    145117    PS_ASSERT_PTR_NON_NULL(config, false);
    146118
    147     bool status = false;
    148     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
    149     if (!status) {
    150         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
    151         return false;
    152     }
     119    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     120    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    153121
    154122    psString query = pxDataGet("dettool_tocorrectexp.sql");
     
    183151    }
    184152
    185     bool simple = false;
    186     {
    187         bool status = false;
    188         simple = psMetadataLookupBool(&status, config->args, "-simple");
    189         if (!status) {
    190             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    191             return false;
    192         }
    193     }
    194 
    195153    // negative simple so the default is true
    196154    if (!ippdbPrintMetadatas(stdout, output, "detRun", !simple)) {
     
    209167    PS_ASSERT_PTR_NON_NULL(config, false);
    210168
    211     bool status = false;
    212     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
    213     if (!status) {
    214         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
    215         return false;
    216     }
     169    psMetadata *where = psMetadataAlloc();
     170    PXOPT_COPY_STR(config->args, where, "-det_type", "det_type", "==");
     171
     172    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     173    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    217174
    218175    psString query = pxDataGet("dettool_tocorrectimfile.sql");
     
    222179    }
    223180
    224     if (config->where) {
    225         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "det1");
     181    if (psListLength(where->list)) {
     182        // NOTE the SQL uses an intermediate table 'det1' for this query
     183        psString whereClause = psDBGenerateWhereConditionSQL(where, "det1");
    226184        psStringAppend(&query, " AND %s", whereClause);
    227185        psFree(whereClause);
    228186    }
     187    psFree (where);
    229188
    230189    // treat limit == 0 as "no limit"
     
    253212    }
    254213
    255     bool simple = false;
    256     {
    257         bool status = false;
    258         simple = psMetadataLookupBool(&status, config->args, "-simple");
    259         if (!status) {
    260             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    261             return false;
    262         }
    263     }
    264 
    265214    // negative simple so the default is true
    266215    if (!ippdbPrintMetadatas(stdout, output, "detPendingCorrectImfile", !simple)) {
     
    275224}
    276225
     226// NOTE : the command-line args are parsed by register_detrend_imfileMode
    277227bool addcorrectimfileMode(pxConfig *config)
    278228{
Note: See TracChangeset for help on using the changeset viewer.