IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9972


Ignore:
Timestamp:
Nov 13, 2006, 5:49:38 PM (20 years ago)
Author:
jhoblitt
Message:

add datastore "time" field handling to pzgetexp

File:
1 edited

Legend:

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

    r9968 r9972  
    4040    bool haveLastFileSet = false;
    4141    psString lastFileSet = NULL;
    42     // XXX this is a very ugly and brute force way of doing things need to add
    43     // a metadatadb function to retrun the last entry without removing it from
    44     // the database
    45     psArray *summitExps = summitExpSelectRowObjects(config->dbh, NULL, 1);
    46     if (!summitExps) {
    47         psError(PS_ERR_UNKNOWN, false, "database error");
    48         goto FAIL;
    49     }
    50     if (psArrayLength(summitExps)) {
    51         haveLastFileSet = true;
    52         summitExpRow *lastExps = summitExps->data[psArrayLength(summitExps) - 1];
    53         lastFileSet = psMemIncrRefCounter(lastExps->exp_id);
     42    {
     43        char *query = "SELECT * from summitExp ORDER BY time DESC LIMIT 1";
     44        if (!p_psDBRunQuery(config->dbh, query)) {
     45            psError(PS_ERR_UNKNOWN, false, "database error");
     46            return false;
     47        }
     48
     49        psArray *output = p_psDBFetchResult(config->dbh);
     50        if (!output) {
     51            psError(PS_ERR_UNKNOWN, false, "database error");
     52            return false;
     53        }
     54        if (!psArrayLength(output)) {
     55            psError(PS_ERR_UNKNOWN, false, "no summitExp rows found");
     56            haveLastFileSet = false;
     57        } else {
     58            haveLastFileSet = true;
     59            bool status = false;
     60            lastFileSet = psMetadataLookupStr(&status, output->data[0], "exp_id");
     61        }
    5462    }
    5563
     
    96104    {
    97105        char *query = "CREATE TEMPORARY TABLE incoming"
    98             " (exp_id VARCHAR(64), camera VARCHAR(64), telescope VARCHAR(64), exp_type VARCHAR(64), uri VARCHAR(255), PRIMARY KEY(exp_id, camera, telescope))"
     106            " (exp_id VARCHAR(64), camera VARCHAR(64), telescope VARCHAR(64), time DATETIME, exp_type VARCHAR(64), uri VARCHAR(255), PRIMARY KEY(exp_id, camera, telescope))"
    99107           " ENGINE=MEMORY";
    100108        if (!p_psDBRunQuery(config->dbh, query)) {
     
    106114
    107115    {
    108         char *query = "INSERT INTO incoming (exp_id, camera, telescope, exp_type, uri) VALUES (?, ?, ?, ?, ?)";
     116        char *query = "INSERT INTO incoming (exp_id, camera, telescope, time, exp_type, uri) VALUES (?, ?, ?, ?, ?, ?)";
    109117
    110118        long inserted = p_psDBRunQueryPrepared(config->dbh, newSummitExps, query);
     
    170178    }
    171179
     180    // split the string into lines
    172181    psList *doc = psStringSplit(str, "\n", false);
    173182
     
    177186    psString line;
    178187    while ((line = psListGetAndIncrement(lineCursor))) {
    179         // XXX debugging
    180         printf("-> %s\n", line);
    181 
    182188        // split line into tokens
    183189        psList *tokens = psStringSplit(line, " ", false);
     
    201207        char *uri       = psListGetAndIncrement(tokenCursor);
    202208        char *exp_id    = psListGetAndIncrement(tokenCursor); // fileset
    203         char *time      = psListGetAndIncrement(tokenCursor); // datetime
     209        char *timeStr   = psListGetAndIncrement(tokenCursor); // datetime
    204210        char *exp_type  = psListGetAndIncrement(tokenCursor); // type
    205 
    206         if (time) {} // silence unused warning
    207211
    208212        // create a new metadata to represent this line and it's values
     
    229233            return NULL;
    230234        }
     235        psTime *time = psTimeFromISO(timeStr, PS_TIME_UTC);
     236        if (!psMetadataAddTime(md, PS_LIST_TAIL, "time", 0, NULL, time)) {
     237            psError(PS_ERR_UNKNOWN, false, "failed to add item telescope");
     238            psFree(time);
     239            psFree(md);
     240            psFree(tokenCursor);
     241            psFree(tokens);
     242            return NULL;
     243        }
     244        psFree(time);
    231245        if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_type", 0, NULL, exp_type)) {
    232246            psError(PS_ERR_UNKNOWN, false, "failed to add item exp_type");
     
    244258        }
    245259
     260        // add the new metadata to the result set
    246261        psArrayAdd(summitExps, 0, md);
    247262
Note: See TracChangeset for help on using the changeset viewer.