IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 13, 2006, 4:00:40 PM (20 years ago)
Author:
jhoblitt
Message:

modernize pztool -seen

File:
1 edited

Legend:

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

    r9735 r9967  
    3232static bool pendingMode(pxConfig *config);
    3333static bool copydoneMode(pxConfig *config);
    34 static bool summitExpPrint(FILE *stream, summitExpRow *summitExp);
     34
    3535static psArray *pztoolPendingExp(pxConfig *config);
    3636static psArray *pztoolPendingImfiles(pxConfig *config);
     
    7878    PS_ASSERT_PTR_NON_NULL(config, false);
    7979
    80     psArray *summit = summitExpSelectRowObjects(config->dbh,
    81         config->where, MAX_ROWS);
    82     if (!summit) {
    83         psError(PS_ERR_UNKNOWN, false, "no summitExp rows found"); \
    84         return false;
    85     }
    86 
    87     psArray *new = newExpSelectRowObjects(config->dbh,
    88         config->where, MAX_ROWS);
    89     if (!new) {
    90         psError(PS_ERR_UNKNOWN, false, "no newExp rows found"); \
    91     }
    92 
    93     if (new) {
    94         for (long i = 0; i < summit->n; i++) {
    95             summitExpRow *summitExp = summit->data[i];
    96             for (long j = 0; j < summit->n; j++) {
    97                 newExpRow *newExp = new->data[j];
    98                 if (strcmp(summitExp->exp_id, newExp->exp_id) == 0) {
    99                     psArrayRemoveData(summit, summitExp);
    100                     // dec the counter as the array just got shorter
    101                     //and we don't want to skip elemnts
    102                     i--;
    103                     break;
    104                 }
    105             }
    106         }
    107         psFree(new);
    108     }
    109 
    110     for (long i = 0; i < summit->n; i++) {
    111         if (!summitExpPrint(stdout, summit->data[i])) {
    112             psError(PS_ERR_UNKNOWN, false,"summitExpPrint() failed");
     80    psString query = psStringCopy(
     81        "SELECT"
     82        "    summitExp.*"
     83        " FROM summitExp"
     84        " LEFT JOIN newExp"
     85        "   USING(exp_id, camera, telescope)"
     86        " WHERE"
     87        "   newExp.exp_id is NULL"
     88        "   AND newExp.camera IS NULL"
     89        "   AND newExp.telescope IS NULL"
     90    );
     91
     92    if (config->where) {
     93        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "newExp");
     94        psStringAppend(&query, " AND %s", whereClause);
     95        psFree(whereClause);
     96    }
     97
     98    if (!p_psDBRunQuery(config->dbh, query)) {
     99        psError(PS_ERR_UNKNOWN, false, "database error");
     100        psFree(query);
     101        return false;
     102    }
     103    psFree(query);
     104
     105    psArray *output = p_psDBFetchResult(config->dbh);
     106    if (!output) {
     107        psError(PS_ERR_UNKNOWN, false, "database error");
     108        return false;
     109    }
     110    if (!psArrayLength(output)) {
     111        psError(PS_ERR_UNKNOWN, false, "no newExp rows found");
     112        psFree(output);
     113        return true;
     114    }
     115
     116    bool simple = false;
     117    {
     118        bool status = false;
     119        simple = psMetadataLookupBool(&status, config->args, "-simple");
     120        if (!status) {
     121            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    113122            return false;
    114123        }
    115124    }
     125
     126    // negative simple so the default is true
     127    if (!ippdbPrintMetadatas(stdout, output, "newExp", !simple)) {
     128        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     129        psFree(output);
     130        return false;
     131    }
     132
     133    psFree(output);
    116134
    117135    return true;
     
    201219
    202220    return false;
    203 }
    204 
    205 static bool summitExpPrint(FILE *stream, summitExpRow *summitExp)
    206 {
    207     PS_ASSERT_PTR_NON_NULL(stream, false);
    208     PS_ASSERT_PTR_NON_NULL(summitExp, false);
    209 
    210     fprintf(stream, "%s %s %s %s %s\n",
    211         summitExp->exp_id,
    212         summitExp->camera,
    213         summitExp->telescope,
    214         summitExp->exp_type,
    215         summitExp->uri
    216     );
    217 
    218     return true;
    219221}
    220222
Note: See TracChangeset for help on using the changeset viewer.