IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 9, 2009, 2:02:24 PM (17 years ago)
Author:
bills
Message:

code to clean up magicDSRuns

File:
1 edited

Legend:

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

    r25800 r25822  
    5757static bool exportrunMode(pxConfig *config);
    5858static bool importrunMode(pxConfig *config);
     59static bool runstateMode(pxConfig *config);
    5960
    6061# define MODECASE(caseName, func) \
     
    9798        MODECASE(CHIPTOOL_MODE_EXPORTRUN,               exportrunMode);
    9899        MODECASE(CHIPTOOL_MODE_IMPORTRUN,               importrunMode);
     100        MODECASE(CHIPTOOL_MODE_RUNSTATE,                runstateMode);
    99101        default:
    100102            psAbort("invalid option (this should not happen)");
     
    15081510    return true;
    15091511}
     1512
     1513static bool runstateMode(pxConfig *config)
     1514{
     1515    PS_ASSERT_PTR_NON_NULL(config, false);
     1516
     1517    psMetadata *where = psMetadataAlloc();
     1518    PXOPT_COPY_S64(config->args, where, "-chip_id",    "chipRun.chip_id", "==");
     1519    PXOPT_COPY_S64(config->args, where, "-exp_id",     "rawExp.exp_id", "==");
     1520    PXOPT_COPY_STR(config->args, where, "-exp_name",   "rawExp.exp_name", "==");
     1521    pxAddLabelSearchArgs (config, where, "-label",     "chipRun.label", "LIKE");
     1522
     1523//    PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
     1524    PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false);
     1525
     1526    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1527    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1528
     1529    psString query = pxDataGet("chiptool_runstate.sql");
     1530    if (!query) {
     1531        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1532        return false;
     1533    }
     1534
     1535    if (psListLength(where->list)) {
     1536        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1537        psStringAppend(&query, " WHERE %s", whereClause);
     1538        psFree(whereClause);
     1539    } else {
     1540        psError(PXTOOLS_ERR_DATA, true, "search parameters or -all are required");
     1541        return false;
     1542    }
     1543    psFree(where);
     1544
     1545    // treat limit == 0 as "no limit"
     1546    if (limit) {
     1547        psString limitString = psDBGenerateLimitSQL(limit);
     1548        psStringAppend(&query, " %s", limitString);
     1549        psFree(limitString);
     1550    }
     1551
     1552    if (!p_psDBRunQuery(config->dbh, query)) {
     1553        psError(PS_ERR_UNKNOWN, false, "database error");
     1554        psFree(query);
     1555        return false;
     1556    }
     1557    psFree(query);
     1558
     1559    psArray *output = p_psDBFetchResult(config->dbh);
     1560    if (!output) {
     1561        psErrorCode err = psErrorCodeLast();
     1562        switch (err) {
     1563            case PS_ERR_DB_CLIENT:
     1564                psError(PXTOOLS_ERR_SYS, false, "database error");
     1565            case PS_ERR_DB_SERVER:
     1566                psError(PXTOOLS_ERR_PROG, false, "database error");
     1567            default:
     1568                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1569        }
     1570
     1571        return false;
     1572    }
     1573    if (!psArrayLength(output)) {
     1574        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     1575        psFree(output);
     1576        return true;
     1577    }
     1578
     1579    if (psArrayLength(output)) {
     1580        // negative simple so the default is true
     1581        if (!ippdbPrintMetadatas(stdout, output, "chipRunState", !simple)) {
     1582            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1583            psFree(output);
     1584            return false;
     1585        }
     1586    }
     1587
     1588    psFree(output);
     1589
     1590    return true;
     1591}
Note: See TracChangeset for help on using the changeset viewer.