Changeset 9972
- Timestamp:
- Nov 13, 2006, 5:49:38 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pzgetexp.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pzgetexp.c
r9968 r9972 40 40 bool haveLastFileSet = false; 41 41 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 } 54 62 } 55 63 … … 96 104 { 97 105 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))" 99 107 " ENGINE=MEMORY"; 100 108 if (!p_psDBRunQuery(config->dbh, query)) { … … 106 114 107 115 { 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 (?, ?, ?, ?, ?, ?)"; 109 117 110 118 long inserted = p_psDBRunQueryPrepared(config->dbh, newSummitExps, query); … … 170 178 } 171 179 180 // split the string into lines 172 181 psList *doc = psStringSplit(str, "\n", false); 173 182 … … 177 186 psString line; 178 187 while ((line = psListGetAndIncrement(lineCursor))) { 179 // XXX debugging180 printf("-> %s\n", line);181 182 188 // split line into tokens 183 189 psList *tokens = psStringSplit(line, " ", false); … … 201 207 char *uri = psListGetAndIncrement(tokenCursor); 202 208 char *exp_id = psListGetAndIncrement(tokenCursor); // fileset 203 char *time = psListGetAndIncrement(tokenCursor); // datetime209 char *timeStr = psListGetAndIncrement(tokenCursor); // datetime 204 210 char *exp_type = psListGetAndIncrement(tokenCursor); // type 205 206 if (time) {} // silence unused warning207 211 208 212 // create a new metadata to represent this line and it's values … … 229 233 return NULL; 230 234 } 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); 231 245 if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_type", 0, NULL, exp_type)) { 232 246 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_type"); … … 244 258 } 245 259 260 // add the new metadata to the result set 246 261 psArrayAdd(summitExps, 0, md); 247 262
Note:
See TracChangeset
for help on using the changeset viewer.
