Changeset 15149 for trunk/ippTools/src/pztool.c
- Timestamp:
- Oct 1, 2007, 11:08:44 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pztool.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pztool.c
r15108 r15149 37 37 38 38 static bool copydoneCompleteExp(pxConfig *config); 39 static psArray *pzGetKnownCameras(pxConfig *config); 40 static psArray *pzArrayAddArray(psArray *array, psArray *input); 39 41 40 42 # define MODECASE(caseName, func) \ … … 218 220 } 219 221 220 // get a list of cameras we've seen exps for 221 if (!p_psDBRunQuery(config->dbh, "SELECT DISTINCT camera FROM summitExp")) { 222 psError(PS_ERR_UNKNOWN, false, "database error"); 223 return false; 224 } 225 226 psArray *cameras = p_psDBFetchResult(config->dbh); 222 psArray *cameras = pzGetKnownCameras(config); 227 223 if (!cameras) { 228 psError(PS_ERR_UNKNOWN, false, "database error"); 229 return false; 230 } 231 if (!psArrayLength(cameras)) { 232 psTrace("pztool", PS_LOG_INFO, "no rows found"); 233 psFree(cameras); 234 return true; 235 } 224 psError(PXTOOLS_ERR_DATA, false, "failed to find any cameras"); 225 return false; 226 } 227 228 // array to hold the aggregate results 229 psArray *output = psArrayAlloc(0); 236 230 237 231 for (long i = 0; i < psArrayLength(cameras); i++) { … … 239 233 if (!query) { 240 234 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 235 psFree(output); 241 236 return false; 242 237 } … … 251 246 } 252 247 248 long camLimit = 0; 249 // avoid possible div by zero 250 if (limit) { 251 // in the case where the limit asked for is less then the number of 252 // cameras we have, return 1 imfile per camera 253 if (limit < psArrayLength(cameras)) { 254 camLimit = 1; 255 } else { 256 camLimit = limit / psArrayLength(cameras); 257 // add the modulous to the first camera in the list 258 if (i == 0) { 259 camLimit += limit % psArrayLength(cameras); 260 } 261 } 262 } 253 263 254 264 // treat limit == 0 as "no limit" 255 if ( limit) {265 if (camLimit) { 256 266 // divide limit by the number of cameras 257 psString limitString = psDBGenerateLimitSQL( (limit / psArrayLength(cameras) || 1));267 psString limitString = psDBGenerateLimitSQL(camLimit); 258 268 psStringAppend(&query, " %s", limitString); 259 269 psFree(limitString); … … 263 273 psError(PS_ERR_UNKNOWN, false, "database error"); 264 274 psFree(query); 275 psFree(output); 265 276 return false; 266 277 } 267 278 psFree(query); 268 279 269 psArray * output = p_psDBFetchResult(config->dbh);270 if (! output) {280 psArray *result = p_psDBFetchResult(config->dbh); 281 if (!result) { 271 282 psError(PS_ERR_UNKNOWN, false, "database error"); 272 return false; 273 } 274 if (!psArrayLength(output)) { 283 psFree(output); 284 return false; 285 } 286 if (!psArrayLength(result)) { 275 287 psTrace("pztool", PS_LOG_INFO, "no rows found"); 288 psFree(result); 276 289 psFree(output); 277 290 return true; 278 291 } 279 292 280 bool simple = false; 281 { 282 bool status = false; 283 simple = psMetadataLookupBool(&status, config->args, "-simple"); 284 if (!status) { 285 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 286 psFree(output); 287 return false; 288 } 289 } 290 291 // negative simple so the default is true 292 if (!ippdbPrintMetadatas(stdout, output, "pzPendingImfile", !simple)) { 293 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 293 // merge this query into the result set 294 pzArrayAddArray(output, result); 295 psFree(result); 296 } 297 298 bool simple = false; 299 { 300 bool status = false; 301 simple = psMetadataLookupBool(&status, config->args, "-simple"); 302 if (!status) { 303 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 294 304 psFree(output); 295 305 return false; 296 306 } 297 307 } 308 309 // negative simple so the default is true 310 if (!ippdbPrintMetadatas(stdout, output, "pzPendingImfile", !simple)) { 311 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 298 312 psFree(output); 299 } 313 return false; 314 } 315 316 psFree(output); 300 317 301 318 return true; … … 580 597 return true; 581 598 } 599 600 static psArray *pzGetKnownCameras(pxConfig *config) 601 { 602 // get a list of cameras we've seen exps for 603 if (!p_psDBRunQuery(config->dbh, "SELECT DISTINCT camera FROM summitExp")) { 604 psError(PS_ERR_UNKNOWN, false, "database error"); 605 return false; 606 } 607 608 psArray *cameras = p_psDBFetchResult(config->dbh); 609 if (!cameras) { 610 psError(PS_ERR_UNKNOWN, false, "database error"); 611 return NULL; 612 } 613 if (!psArrayLength(cameras)) { 614 psTrace("pztool", PS_LOG_INFO, "no rows found"); 615 psFree(cameras); 616 return psArrayAlloc(0); 617 } 618 619 return cameras; 620 } 621 622 static psArray *pzArrayAddArray(psArray *array, psArray *input) 623 { 624 for (long i = 0; i < psArrayLength(input); i++) { 625 psArrayAdd(array, psArrayLength(input), input->data[i]); 626 } 627 628 return array; 629 }
Note:
See TracChangeset
for help on using the changeset viewer.
