IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 9, 2007, 4:03:20 PM (19 years ago)
Author:
jhoblitt
Message:

add -addruns & -runs

File:
1 edited

Legend:

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

    r15564 r15570  
    197197static bool addrunMode(pxConfig *config)
    198198{
    199     PS_ASSERT_PTR_NON_NULL(config, NULL);
     199    PS_ASSERT_PTR_NON_NULL(config, false);
     200
     201    // required options
     202    bool status = false;
     203    psString cal_id = psMetadataLookupStr(&status, config->args, "-cal_id");
     204    if (!status) {
     205        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -cal_id");
     206        return false;
     207    }
     208    if (!cal_id) {
     209        psError(PS_ERR_UNKNOWN, true, "-cal_id is required");
     210        return false;
     211    }
     212
     213    psString region = psMetadataLookupStr(&status, config->args, "-region");
     214    if (!status) {
     215        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -region");
     216        return false;
     217    }
     218    if (!region) {
     219        psError(PS_ERR_UNKNOWN, true, "-region is required");
     220        return false;
     221    }
     222
     223    psString last_step = psMetadataLookupStr(&status, config->args, "-last_step");
     224    if (!status) {
     225        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -last_step");
     226        return false;
     227    }
     228    if (!last_step) {
     229        psError(PS_ERR_UNKNOWN, true, "-last_step is required");
     230        return false;
     231    }
     232
     233    psString state = psMetadataLookupStr(&status, config->args, "-state");
     234    if (!status) {
     235        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -state");
     236        return false;
     237    }
     238    if (!state) {
     239        psError(PS_ERR_UNKNOWN, true, "-state is required");
     240        return false;
     241    }
     242
     243    if (!calRunInsert(config->dbh,
     244            (psS64)atoll(cal_id),
     245            region,
     246            last_step,
     247            state
     248        )) {
     249        psError(PS_ERR_UNKNOWN, false, "database error");
     250        return false;
     251
     252    }
    200253
    201254    return false;
     
    205258static bool runsMode(pxConfig *config)
    206259{
    207     PS_ASSERT_PTR_NON_NULL(config, NULL);
    208 
    209     return false;
    210 }
     260    PS_ASSERT_PTR_NON_NULL(config, false);
     261
     262    bool status = false;
     263    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
     264    if (!status) {
     265        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
     266        return false;
     267    }
     268
     269    psString query = psStringCopy("SELECT * FROM calRun");
     270
     271    if (config->where) {
     272        psString whereClause = psDBGenerateWhereSQL(config->where, NULL);
     273        psStringAppend(&query, " %s", whereClause);
     274        psFree(whereClause);
     275    }
     276
     277    // treat limit == 0 as "no limit"
     278    if (limit) {
     279        psString limitString = psDBGenerateLimitSQL(limit);
     280        psStringAppend(&query, " %s", limitString);
     281        psFree(limitString);
     282    }
     283
     284    if (!p_psDBRunQuery(config->dbh, query)) {
     285        psError(PS_ERR_UNKNOWN, false, "database error");
     286        psFree(query);
     287        return false;
     288    }
     289    psFree(query);
     290
     291    psArray *output = p_psDBFetchResult(config->dbh);
     292    if (!output) {
     293        psErrorCode err = psErrorCodeLast();
     294        switch (err) {
     295            case PS_ERR_DB_CLIENT:
     296                psError(PXTOOLS_ERR_SYS, false, "database error");
     297            case PS_ERR_DB_SERVER:
     298                psError(PXTOOLS_ERR_PROG, false, "database error");
     299            default:
     300                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     301        }
     302
     303        return false;
     304    }
     305    if (!psArrayLength(output)) {
     306        psTrace("caltool", PS_LOG_INFO, "no rows found");
     307        psFree(output);
     308        return true;
     309    }
     310
     311    bool simple = false;
     312    {
     313        bool status = false;
     314        simple = psMetadataLookupBool(&status, config->args, "-simple");
     315        if (!status) {
     316            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
     317            return false;
     318        }
     319    }
     320
     321    if (psArrayLength(output)) {
     322        if (!convertIdToStr(output)) {
     323            psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
     324            psFree(output);
     325            return false;
     326        }
     327
     328        // negative simple so the default is true
     329        if (!ippdbPrintMetadatas(stdout, output, "calRun", !simple)) {
     330            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     331            psFree(output);
     332            return false;
     333        }
     334    }
     335
     336    psFree(output);
     337
     338    return true;
     339}
Note: See TracChangeset for help on using the changeset viewer.