IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 26, 2007, 3:21:43 PM (19 years ago)
Author:
jhoblitt
Message:

add dettool -orphanrun

File:
1 edited

Legend:

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

    r12058 r12065  
    3535static bool definebydetrunMode(pxConfig *config);
    3636static bool runsMode(pxConfig *config);
     37static bool orphanrunMode(pxConfig *config);
    3738static bool inputMode(pxConfig *config);
    3839static bool rawMode(pxConfig *config);
     
    106107        MODECASE(DETTOOL_MODE_DEFINEBYDETRUN,   definebydetrunMode);
    107108        MODECASE(DETTOOL_MODE_RUNS,             runsMode);
     109        MODECASE(DETTOOL_MODE_ORPHANRUN,        orphanrunMode);
    108110        MODECASE(DETTOOL_MODE_INPUT,            inputMode);
    109111        MODECASE(DETTOOL_MODE_RAW,              rawMode);
     
    17141716
    17151717    psFree(runs);
     1718
     1719    return true;
     1720}
     1721
     1722static bool orphanrunMode(pxConfig *config)
     1723{
     1724    PS_ASSERT_PTR_NON_NULL(config, false);
     1725
     1726    psString query = psStringCopy(
     1727            "SELECT\n"
     1728            "   detRun.*\n"
     1729            " FROM detRun\n"
     1730            " LEFT JOIN detRun as foo\n"
     1731            "   ON foo.parent = detRun.det_id\n"
     1732            " WHERE"
     1733            "   detRun.state = 'stop'"
     1734            "   AND detRun.mode = 'master'"
     1735        );
     1736
     1737    if (config->where) {
     1738        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detRun");
     1739        psStringAppend(&query, " AND %s", whereClause);
     1740        psFree(whereClause);
     1741    }
     1742
     1743    if (!p_psDBRunQuery(config->dbh, query)) {
     1744        psError(PS_ERR_UNKNOWN, false, "database error");
     1745        psFree(query);
     1746        return false;
     1747    }
     1748    psFree(query);
     1749
     1750    psArray *output = p_psDBFetchResult(config->dbh);
     1751    if (!output) {
     1752        psError(PS_ERR_UNKNOWN, false, "database error");
     1753        return false;
     1754    }
     1755    if (!psArrayLength(output)) {
     1756        // XXX check psError here
     1757        psError(PS_ERR_UNKNOWN, false, "no orphan detRun rows found");
     1758        psFree(output);
     1759        return true;
     1760    }
     1761
     1762    // convert det_id to a string externaly
     1763    if (!convertDetIdToStr(output)) {
     1764        psError(PS_ERR_UNKNOWN, false, "failed to convert det_id to a string");
     1765        psFree(output);
     1766        return false;
     1767    }
     1768
     1769    bool simple = false;
     1770    {
     1771        bool status = false;
     1772        simple = psMetadataLookupBool(&status, config->args, "-simple");
     1773        if (!status) {
     1774            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
     1775            psFree(output);
     1776            return false;
     1777        }
     1778    }
     1779
     1780    // negative simple so the default is true
     1781    if (!ippdbPrintMetadatas(stdout, output, "detRun", !simple)) {
     1782        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1783        psFree(output);
     1784        return false;
     1785    }
     1786
     1787    psFree(output);
    17161788
    17171789    return true;
Note: See TracChangeset for help on using the changeset viewer.