IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 1, 2006, 5:55:20 PM (20 years ago)
Author:
jhoblitt
Message:

add multiple -exp_id support to -define

File:
1 edited

Legend:

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

    r7248 r7293  
    9999static bool defineMode(pxConfig *config)
    100100{
     101    bool status     = false;
    101102    psString str    = NULL;
    102     bool status     = false;
    103103
    104104    PS_ASSERT_PTR_NON_NULL(config, false);
    105105
     106    // start a transaction so we don't end up with orphaned det_ids
    106107    if (!psDBTransaction(config->dbh)) {
    107108        psError(PS_ERR_UNKNOWN, false, "database error");
    108        
     109        return false;
    109110    }
    110111
    111112    // what type of detRun is this?
    112113    // XXX make this flag required
    113     str = psMetadataLookupStr(&status, config->args, "-det_type");
    114    
    115     // XXX the value being inserted is junk as we can't yet have an 'empty
    116     // table'
    117     detRunInsert(config->dbh, str);
     114    psString det_type = psMetadataLookupStr(&status, config->args, "-det_type");
     115    detRunInsert(config->dbh, det_type);
    118116    long det_id = psDBLastInsertID(config->dbh);
    119117   
    120     // XXX this needs to fixed to support multipe exp_ids
     118    // we have to support multipe exp_ids
     119    psMetadataItem *item = psMetadataLookup(config->args, "-exp_id");
    121120    psMetadata *where = psMetadataAlloc();
    122     if ((str = psMetadataLookupStr(&status, config->args, "-exp_id"))) {
     121
     122    // was more then one exp_id specified?
     123    if (item->type == PS_DATA_METADATA_MULTI) {
     124        // yes
     125        psListIterator *iter = psListIteratorAlloc(item->data.list, 0, false);
     126        psMetadataItem *mItem = NULL;
     127        while ((mItem = psListGetAndIncrement(iter))) {
     128            psString exp_id = mItem->data.V;
     129            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id",
     130                        PS_META_DUPLICATE_OK, "==", exp_id)) {
     131                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
     132                // rollback
     133                if (!psDBRollback(config->dbh)) {
     134                    psError(PS_ERR_UNKNOWN, false, "database error");
     135                }
     136                psFree(iter);
     137                psFree(where);
     138                return false;
     139            }
     140        }
     141    } else if ((str = psMetadataLookupStr(&status, config->args, "-exp_id"))) {
     142        // no
    123143        if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==", str)) {
    124144            psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
     
    137157    }
    138158
     159    // check that the specified exp_ids actually exist
    139160    psArray *rawExps = rawDetrendExpSelectRowObjects(config->dbh, where, 0);
    140161    psFree(where);
     
    148169    }
    149170
    150     detInputExpRow *detInputExp = rawDetrenTodetInputExpRow(
    151         rawExps->data[0],
    152         det_id
    153     );
    154 
    155     if (!detInputExpInsertObject(config->dbh, detInputExp)) {
    156         psError(PS_ERR_UNKNOWN, false, "database error");
    157         // rollback
    158         if (!psDBRollback(config->dbh)) {
     171    if (item->type == PS_DATA_METADATA_MULTI) {
     172        // we should have one rawExp row be exp_id specified
     173        if (psListLength(item->data.list) != psArrayLength(rawExps)) {
     174            // rollback
     175            if (!psDBRollback(config->dbh)) {
     176                psError(PS_ERR_UNKNOWN, false, "database error");
     177            }
     178            psAbort(config->argv[0],
     179        "an -exp_id matched more then one rawExp (this should not happen");
     180
     181        }
     182    } else {
     183        // we should have matched only one exp_id
     184        if (psArrayLength(rawExps) != 1) {
     185            // rollback
     186            if (!psDBRollback(config->dbh)) {
     187                psError(PS_ERR_UNKNOWN, false, "database error");
     188            }
     189            psAbort(config->argv[0],
     190        "an -exp_id matched more then one rawExp (this should not happen");
     191        }
     192    }
     193
     194    // create new detInputExp row(s) from the rawExp row(s)
     195    psArray *inputExps = psArrayAlloc(psArrayLength(rawExps));
     196    for (long i = 0; i < psArrayLength(rawExps); i++) {
     197        detInputExpRow *inputExp = rawDetrenTodetInputExpRow(
     198            rawExps->data[i],
     199            det_id
     200        );
     201        psArrayAdd(inputExps, 0, inputExp);
     202        psFree(inputExp);
     203    }
     204
     205    for (long i = 0; i < psArrayLength(inputExps); i++) {
     206        if (!detInputExpInsertObject(config->dbh, inputExps->data[i])) {
    159207            psError(PS_ERR_UNKNOWN, false, "database error");
    160         }
    161         return false;
     208            // rollback
     209            if (!psDBRollback(config->dbh)) {
     210                psError(PS_ERR_UNKNOWN, false, "database error");
     211            }
     212            return false;
     213        }
    162214    }
    163215
Note: See TracChangeset for help on using the changeset viewer.