IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15564


Ignore:
Timestamp:
Nov 9, 2007, 3:38:56 PM (19 years ago)
Author:
jhoblitt
Message:

impliement -adddb and -dbs

File:
1 edited

Legend:

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

    r15545 r15564  
    8383static bool adddbMode(pxConfig *config)
    8484{
     85    PS_ASSERT_PTR_NON_NULL(config, false);
     86
     87    // required options
     88    bool status = false;
     89    psString dvodb = psMetadataLookupStr(&status, config->args, "-dvodb");
     90    if (!status) {
     91        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -dvodb");
     92        return false;
     93    }
     94    if (!dvodb) {
     95        psError(PS_ERR_UNKNOWN, true, "-dvodb is required");
     96        return false;
     97    }
     98
     99    if (!calDBInsert(config->dbh,
     100            0,       // cal_id
     101            dvodb,
     102            "active"    // state
     103        )) {
     104        psError(PS_ERR_UNKNOWN, false, "database error");
     105        return false;
     106
     107    }
     108
     109    return false;
     110}
     111
     112
     113static bool dbsMode(pxConfig *config)
     114{
     115    PS_ASSERT_PTR_NON_NULL(config, false);
     116
     117    bool status = false;
     118    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
     119    if (!status) {
     120        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
     121        return false;
     122    }
     123
     124    psString query = psStringCopy("SELECT * FROM calDB");
     125
     126    if (config->where) {
     127        psString whereClause = psDBGenerateWhereSQL(config->where, NULL);
     128        psStringAppend(&query, " %s", whereClause);
     129        psFree(whereClause);
     130    }
     131
     132    // treat limit == 0 as "no limit"
     133    if (limit) {
     134        psString limitString = psDBGenerateLimitSQL(limit);
     135        psStringAppend(&query, " %s", limitString);
     136        psFree(limitString);
     137    }
     138
     139    if (!p_psDBRunQuery(config->dbh, query)) {
     140        psError(PS_ERR_UNKNOWN, false, "database error");
     141        psFree(query);
     142        return false;
     143    }
     144    psFree(query);
     145
     146    psArray *output = p_psDBFetchResult(config->dbh);
     147    if (!output) {
     148        psErrorCode err = psErrorCodeLast();
     149        switch (err) {
     150            case PS_ERR_DB_CLIENT:
     151                psError(PXTOOLS_ERR_SYS, false, "database error");
     152            case PS_ERR_DB_SERVER:
     153                psError(PXTOOLS_ERR_PROG, false, "database error");
     154            default:
     155                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     156        }
     157
     158        return false;
     159    }
     160    if (!psArrayLength(output)) {
     161        psTrace("caltool", PS_LOG_INFO, "no rows found");
     162        psFree(output);
     163        return true;
     164    }
     165
     166    bool simple = false;
     167    {
     168        bool status = false;
     169        simple = psMetadataLookupBool(&status, config->args, "-simple");
     170        if (!status) {
     171            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
     172            return false;
     173        }
     174    }
     175
     176    if (psArrayLength(output)) {
     177        if (!convertIdToStr(output)) {
     178            psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
     179            psFree(output);
     180            return false;
     181        }
     182
     183        // negative simple so the default is true
     184        if (!ippdbPrintMetadatas(stdout, output, "calDB", !simple)) {
     185            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     186            psFree(output);
     187            return false;
     188        }
     189    }
     190
     191    psFree(output);
     192
     193    return true;
     194}
     195
     196
     197static bool addrunMode(pxConfig *config)
     198{
    85199    PS_ASSERT_PTR_NON_NULL(config, NULL);
    86200
     
    89203
    90204
    91 static bool dbsMode(pxConfig *config)
     205static bool runsMode(pxConfig *config)
    92206{
    93207    PS_ASSERT_PTR_NON_NULL(config, NULL);
     
    95209    return false;
    96210}
    97 
    98 
    99 static bool addrunMode(pxConfig *config)
    100 {
    101     PS_ASSERT_PTR_NON_NULL(config, NULL);
    102 
    103     return false;
    104 }
    105 
    106 
    107 static bool runsMode(pxConfig *config)
    108 {
    109     PS_ASSERT_PTR_NON_NULL(config, NULL);
    110 
    111     return false;
    112 }
Note: See TracChangeset for help on using the changeset viewer.