IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 30, 2013, 4:48:58 PM (13 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/eam_branches/ipp-20130711/ippTools/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130711/ippTools/src

  • branches/eam_branches/ipp-20130711/ippTools/src/stacktool.c

    r34800 r36071  
    4444static bool tosummaryMode(pxConfig *config);
    4545static bool addsummaryMode(pxConfig *config);
     46static bool summaryMode(pxConfig *config);
    4647static bool pendingcleanuprunMode(pxConfig *config);
    4748static bool pendingcleanupskyfileMode(pxConfig *config);
     
    8485        MODECASE(STACKTOOL_MODE_TOSUMMARY,             tosummaryMode);
    8586        MODECASE(STACKTOOL_MODE_ADDSUMMARY,            addsummaryMode);
     87        MODECASE(STACKTOOL_MODE_SUMMARY,               summaryMode);
    8688        MODECASE(STACKTOOL_MODE_PENDINGCLEANUPRUN,     pendingcleanuprunMode);
    8789        MODECASE(STACKTOOL_MODE_PENDINGCLEANUPSKYFILE, pendingcleanupskyfileMode);
     
    748750    PXOPT_COPY_S64(config->args, where, "-stack_id",  "stackRun.stack_id",   "==");
    749751    PXOPT_COPY_STR(config->args, where, "-label",     "stackRun.label",     "==");
     752    PXOPT_COPY_STR(config->args, where, "-data_group", "stackRun.data_group", "==");
    750753    PXOPT_COPY_STR(config->args, where, "-state",     "stackRun.state",     "==");
    751754    PXOPT_COPY_S64(config->args, where, "-sass_id",   "stackAssociationMap.sass_id",  "==");
     
    14751478  // generate where strings for arguments that require extra processing
    14761479  // beyond PXOPT_COPY*
     1480  psString whereClause;
    14771481  if (psListLength(where->list)) {
    1478     psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    1479     psStringAppend(&query, " AND %s", whereClause);
    1480     psFree(whereClause);
     1482    whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1483    psStringPrepend(&whereClause, "\n AND ");
    14811484  } else if (!all) {
    14821485    psError(PXTOOLS_ERR_CONFIG, true, "search parameters or -all are required");
     1486    psFree(whereClause);
    14831487    return false;
    14841488  }
     
    14931497  }
    14941498
    1495   if (!p_psDBRunQuery(config->dbh, query)) {
     1499  if (!p_psDBRunQueryF(config->dbh, query, whereClause)) {
    14961500    psError(PS_ERR_UNKNOWN, false, "database error");
     1501    psFree(whereClause);
    14971502    psFree(query);
    14981503    return false;
    14991504  }
     1505  psFree(whereClause);
    15001506  psFree(query);
    15011507
     
    15641570}
    15651571
     1572static bool summaryMode(pxConfig *config)
     1573{
     1574    PS_ASSERT_PTR_NON_NULL(config, false);
     1575
     1576    psMetadata *where = psMetadataAlloc();
     1577    PXOPT_COPY_S64(config->args, where, "-sass_id", "stackSummary.sass_id", "==");
     1578    PXOPT_COPY_STR(config->args, where, "-projection_cell", "stackAssociation.projection_cell", "==");
     1579    PXOPT_COPY_STR(config->args, where, "-tess_id", "stackAssociation.tess_id", "LIKE");
     1580    PXOPT_COPY_STR(config->args, where, "-filter", "stackAssociation.filter", "LIKE");
     1581    PXOPT_COPY_S64(config->args, where, "-stack_id", "stackSumSkyfile.stack_id", "==");
     1582    pxAddLabelSearchArgs(config, where, "-data_group", "stackAssociation.data_group", "LIKE");
     1583    PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "LIKE");
     1584//    PXOPT_COPY_STR(config->args, where, "-state", "stackRun.state", "==");
     1585    pxAddLabelSearchArgs(config, where, "-label", "stackRun.label", "LIKE");
     1586//    PXOPT_COPY_S16(config->args, where, "-fault", "stackSumSkyfile.fault", "==");
     1587//    PXOPT_COPY_F64(config->args, where, "-mjd_obs_begin", "stackSumSkyfile.mjd_obs", ">=");
     1588//    PXOPT_COPY_F64(config->args, where, "-mjd_obs_end", "stackSumSkyfile.mjd_obs", "<=");
     1589//    PXOPT_COPY_S16(config->args, where, "-background_model","stackSumSkyfile.background_model", "==");
     1590
     1591//    PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
     1592
     1593    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1594    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1595
     1596    psString query = pxDataGet("stacktool_summary.sql");
     1597    if (!query) {
     1598        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1599        return false;
     1600    }
     1601
     1602    if (psListLength(where->list)) {
     1603        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1604        psStringAppend(&query, " WHERE %s", whereClause);
     1605        psFree(whereClause);
     1606    } else {
     1607        psError(PXTOOLS_ERR_CONFIG, true, "search parameters are required");
     1608        return false;
     1609    }
     1610
     1611    psFree(where);
     1612
     1613    // treat limit == 0 as "no limit"
     1614    if (limit) {
     1615        psString limitString = psDBGenerateLimitSQL(limit);
     1616        psStringAppend(&query, " %s", limitString);
     1617        psFree(limitString);
     1618    }
     1619
     1620    if (!p_psDBRunQuery(config->dbh, query)) {
     1621        psError(PS_ERR_UNKNOWN, false, "database error");
     1622        psFree(query);
     1623        return false;
     1624    }
     1625    psFree(query);
     1626
     1627    psArray *output = p_psDBFetchResult(config->dbh);
     1628    if (!output) {
     1629        psErrorCode err = psErrorCodeLast();
     1630        switch (err) {
     1631            case PS_ERR_DB_CLIENT:
     1632                psError(PXTOOLS_ERR_SYS, false, "database error");
     1633            case PS_ERR_DB_SERVER:
     1634                psError(PXTOOLS_ERR_PROG, false, "database error");
     1635            default:
     1636                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1637        }
     1638
     1639        return false;
     1640    }
     1641    if (!psArrayLength(output)) {
     1642        psTrace("stacktool", PS_LOG_INFO, "no rows found");
     1643        psFree(output);
     1644        return true;
     1645    }
     1646
     1647    if (psArrayLength(output)) {
     1648        if (!ippdbPrintMetadatas(stdout, output, "stackSummary", !simple)) {
     1649            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1650            psFree(output);
     1651            return false;
     1652        }
     1653    }
     1654
     1655    psFree(output);
     1656
     1657    return true;
     1658}
     1659
    15661660static bool pendingcleanuprunMode(pxConfig *config)
    15671661{
Note: See TracChangeset for help on using the changeset viewer.