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/magictool.c

    r18336 r18496  
    103103
    104104    // create warped skycells temp table
    105 {
    106     char *query =
    107         "CREATE TEMPORARY TABLE warpComplete\n"
    108         " (warp_id BIGINT, skycell_id VARCHAR(64), tess_id VARCHAR(64),\n"
    109         " PRIMARY KEY(warp_id, skycell_id, tess_id)) ENGINE=MEMORY\n";
    110 
    111     if (!p_psDBRunQuery(config->dbh, query)) {
    112         psError(PS_ERR_UNKNOWN, false, "database error");
    113         return false;
    114     }
    115 }
     105    {
     106        psString query = pxDataGet("magictool_create_tmp_warpcomplete.sql");
     107        if (!query) {
     108            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     109            return false;
     110        }
     111
     112        if (!p_psDBRunQuery(config->dbh, query)) {
     113            psError(PS_ERR_UNKNOWN, false, "database error");
     114            return false;
     115        }
     116    }
    116117
    117118    // find warped skycells
    118 {
    119     psString query = pxDataGet("magictool_find_complete_warpruns.sql");
    120     if (!query) {
    121         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    122         return false;
    123     }
    124 
    125     if (!p_psDBRunQuery(config->dbh, query)) {
    126         psError(PS_ERR_UNKNOWN, false, "database error");
    127         psFree(query);
    128         return false;
    129     }
    130     psFree(query);
    131 }
     119    {
     120        psString query = pxDataGet("magictool_find_complete_warpruns.sql");
     121        if (!query) {
     122            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     123            return false;
     124        }
     125
     126        if (!p_psDBRunQuery(config->dbh, query)) {
     127            psError(PS_ERR_UNKNOWN, false, "database error");
     128            psFree(query);
     129            return false;
     130        }
     131        psFree(query);
     132    }
    132133
    133134    // find the diff_id's of the warped skycells
    134 {
    135     psString query = pxDataGet("magictool_find_complete_diffed_exposures.sql");
    136     if (!query) {
    137         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    138         return false;
    139     }
    140 
    141     if (!p_psDBRunQuery(config->dbh, query)) {
    142         psError(PS_ERR_UNKNOWN, false, "database error");
    143         psFree(query);
    144         return false;
    145     }
    146     psFree(query);
    147 }
     135    {
     136        psString query = pxDataGet("magictool_find_complete_diffed_exposures.sql");
     137        if (!query) {
     138            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     139            return false;
     140        }
     141
     142        if (!p_psDBRunQuery(config->dbh, query)) {
     143            psError(PS_ERR_UNKNOWN, false, "database error");
     144            psFree(query);
     145            return false;
     146        }
     147        psFree(query);
     148    }
    148149    psArray *output = p_psDBFetchResult(config->dbh);
    149150    if (!output) {
    150151        psErrorCode err = psErrorCodeLast();
    151152        switch (err) {
    152             case PS_ERR_DB_CLIENT:
    153                 psError(PXTOOLS_ERR_SYS, false, "database error");
    154             case PS_ERR_DB_SERVER:
    155                 psError(PXTOOLS_ERR_PROG, false, "database error");
    156             default:
    157                 psError(PXTOOLS_ERR_PROG, false, "unknown error");
     153          case PS_ERR_DB_CLIENT:
     154            psError(PXTOOLS_ERR_SYS, false, "database error");
     155          case PS_ERR_DB_SERVER:
     156            psError(PXTOOLS_ERR_PROG, false, "database error");
     157          default:
     158            psError(PXTOOLS_ERR_PROG, false, "unknown error");
    158159        }
    159160
     
    205206
    206207        magicRunRow *run = magicRunRowAlloc(
    207                 0,          // ID
    208                 "reg",      // state
    209                 NULL,       // workdir
    210                 "dirty",    // workdir_state
    211                 NULL,       // label
    212                 NULL,       // dvodb
    213                 NULL        // registered
    214         );
     208            0,          // ID
     209            "reg",      // state
     210            NULL,       // workdir
     211            "dirty",    // workdir_state
     212            NULL,       // label
     213            NULL,       // dvodb
     214            NULL        // registered
     215            );
    215216        if (!run) {
    216217            psAbort("failed to alloc magicRun object");
     
    241242
    242243            if (!magicInputSkyfileInsert(config->dbh,
    243                 magic_id,
    244                 diff_id,
    245                 node)) {
     244                                        magic_id,
     245                                        diff_id,
     246                                        node)) {
    246247                psError(PS_ERR_UNKNOWN, false, "database error");
    247248                psFree(grouped);
     
    268269    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
    269270    PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false);
     271    PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
    270272    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    271     PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
    272273
    273274    magicRunRow *run = magicRunRowAlloc(
     
    348349    PS_ASSERT_PTR_NON_NULL(config, false);
    349350
     351    psMetadata *where = psMetadataAlloc();
     352    PXOPT_COPY_STR(config->args, where, "-magic_id", "magic_id", "==");
     353    PXOPT_COPY_STR(config->args, where, "-diff_id", "diff_id", "==");
     354    PXOPT_COPY_STR(config->args, where, "-node", "node", "==");
     355
    350356    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    351357    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     
    358364    }
    359365
    360     if (config->where) {
    361         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "magicInputSkyfile");
     366    if (psListLength(where->list)) {
     367        psString whereClause = psDBGenerateWhereConditionSQL(where, "magicInputSkyfile");
    362368        psStringAppend(&query, " AND %s", whereClause);
    363369        psFree(whereClause);
    364370    }
     371    psFree(where);
    365372
    366373    // treat limit == 0 as "no limit"
     
    500507    PS_ASSERT_PTR_NON_NULL(config, false);
    501508
    502     PXOPT_LOOKUP_STR(magic_id, config->args, "-magic_id", false, false);
     509    psMetadata *where = psMetadataAlloc();
     510    PXOPT_COPY_STR(config->args, where, "-magic_id", "magic_id", "==");
     511
     512    psString whereClause = NULL;
     513    if (psListLength(where->list)) {
     514        whereClause = psDBGenerateWhereSQL(where, NULL);
     515    }
     516    psFree(where);
     517
    503518    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    504519
     
    510525    }
    511526
    512     if (magic_id) {
    513         psMetadata *where = psMetadataAlloc();
    514         psMetadataAddS64(where, PS_LIST_TAIL, "magic_id", 0, "==", (psS64)atoll(magic_id));
    515         psString whereClause = psDBGenerateWhereSQL(where, NULL);
    516         psFree(where);
     527    if (whereClause) {
    517528        psStringAppend(&query, " %s", whereClause);
    518         psFree(whereClause);
    519529    }
    520530
     
    542552    if (!psArrayLength(output)) {
    543553        psTrace("magictool", PS_LOG_INFO, "no rows found");
    544 //        psFree(output);
    545 //        return true;
     554        // psFree(output);
     555        // return true;
    546556    }
    547557
     
    553563    }
    554564
    555 
    556     if (magic_id) {
    557         psMetadata *where = psMetadataAlloc();
    558         psMetadataAddS64(where, PS_LIST_TAIL, "magic_id", 0, "==", (psS64)atoll(magic_id));
    559         psString whereClause = psDBGenerateWhereSQL(where, NULL);
    560         psFree(where);
     565    if (whereClause) {
    561566        psStringAppend(&query, " %s", whereClause);
    562         psFree(whereClause);
    563567    }
    564568
     
    613617    pxNode *root = psHashLookup(forest, "root");
    614618    psFree(forest);
    615 //    pxTreePrint(stdout, root);
     619    // pxTreePrint(stdout, root);
    616620
    617621    // crawl through the tree and looking for nodes with children that are all
     
    630634
    631635    psFree(output);
     636    psFree(whereClause);
    632637
    633638    return true;
     
    744749    PS_ASSERT_PTR_NON_NULL(config, false);
    745750
     751    psMetadata *where = psMetadataAlloc();
     752    PXOPT_COPY_STR(config->args, where, "-magic_id", "magic_id", "==");
     753
    746754    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    747755    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     
    752760        return false;
    753761    }
     762
     763    if (psListLength(where->list)) {
     764        psString whereClause = psDBGenerateWhereConditionSQL(where, "magicRun");
     765        psStringAppend(&query, " AND %s", whereClause);
     766        psFree(whereClause);
     767    }
     768    psFree(where);
    754769
    755770    // treat limit == 0 as "no limit"
Note: See TracChangeset for help on using the changeset viewer.