Changeset 14600 for trunk/ippTools/src/pztool.c
- Timestamp:
- Aug 21, 2007, 4:27:42 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pztool.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pztool.c
r14023 r14600 35 35 static bool copydoneMode(pxConfig *config); 36 36 37 static bool copydoneCompleteExp(pxConfig *config); 38 37 39 # define MODECASE(caseName, func) \ 38 40 case caseName: \ … … 196 198 psString query = psStringCopy( 197 199 "SELECT" 198 " summitImfile.*," 199 " pzPendingImfile.exp_id" 200 " summitImfile.*" 200 201 " FROM pzPendingImfile" 201 202 " JOIN summitImfile" … … 324 325 } 325 326 326 // insert new imfile into newImfile327 {328 char *query =329 "INSERT INTO newImfile"330 " SElECT"331 " pzPendingImfile.exp_id,"332 " pzPendingImfile.class,"333 " pzPendingImfile.class_id,"334 " '%s'," // uri of downloaded file335 " 0" // error flags336 " FROM pzPendingImfile"337 " WHERE"338 " pzPendingImfile.exp_name = '%s'"339 " AND pzPendingImfile.camera = '%s'"340 " AND pzPendingImfile.telescope = '%s'"341 " AND pzPendingImfile.class = '%s'"342 " AND pzPendingImfile.class_id = '%s'";343 344 if (!p_psDBRunQuery(config->dbh, query, uri, exp_name, camera, telescope, class, class_id)) {345 // rollback346 if (!psDBRollback(config->dbh)) {347 psError(PS_ERR_UNKNOWN, false, "database error");348 }349 psError(PS_ERR_UNKNOWN, false, "database error");350 return false;351 }352 353 // sanity check: we should have inserted only one row354 psU64 affected = psDBAffectedRows(config->dbh);355 if (psDBAffectedRows(config->dbh) != 1) {356 // rollback357 if (!psDBRollback(config->dbh)) {358 psError(PS_ERR_UNKNOWN, false, "database error");359 }360 psError(PS_ERR_UNKNOWN, false, "should have affected 1 row but %" PRIu64 " rows were modified", affected);361 return false;362 }363 }364 327 365 328 // cp the imfile into pzDoneImfile … … 441 404 } 442 405 406 if (!copydoneCompleteExp(config)) { 407 psError(PS_ERR_UNKNOWN, false, "copydoneCompleteExp() failed"); 408 return false; 409 } 410 443 411 return true; 444 412 } 413 414 static bool copydoneCompleteExp(pxConfig *config) 415 { 416 PS_ASSERT_PTR_NON_NULL(config, false); 417 418 // find all exposures that have had all of their imfiles downloaded but do 419 // not appear in newExp 420 psString query = pxDataGet("pztool_find_completed_exp.sql"); 421 if (!query) { 422 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 423 return false; 424 } 425 426 if (!p_psDBRunQuery(config->dbh, query)) { 427 psError(PS_ERR_UNKNOWN, false, "database error"); 428 psFree(query); 429 return false; 430 } 431 psFree(query); 432 433 psArray *output = p_psDBFetchResult(config->dbh); 434 if (!output) { 435 psError(PS_ERR_UNKNOWN, false, "database error"); 436 return false; 437 } 438 if (!psArrayLength(output)) { 439 psTrace("pztool", PS_LOG_INFO, "no rows found"); 440 psFree(output); 441 return true; 442 } 443 444 // start a transaction so all newExp's can start off with a state of run 445 if (!psDBTransaction(config->dbh)) { 446 psError(PS_ERR_UNKNOWN, false, "database error"); 447 psFree(output); 448 return false; 449 } 450 451 452 for (long i = 0; i < psArrayLength(output); i++) { 453 psMetadata *row = output->data[i]; 454 455 pzDoneExpRow *doneExp = pzDoneExpObjectFromMetadata(row); 456 457 if (!newExpInsert(config->dbh, 458 0x0, // exp_id 459 doneExp->exp_name, // tmp_exp_name 460 doneExp->camera, // tmp_camera 461 doneExp->telescope, // tmp_telescope 462 "run", // state 463 NULL, // workdir 464 "dirty", // workdir state 465 NULL // reduction class 466 ) 467 ) { 468 // rollback 469 if (!psDBRollback(config->dbh)) { 470 psError(PS_ERR_UNKNOWN, false, "database error"); 471 } 472 psError(PS_ERR_UNKNOWN, false, "database error"); 473 psFree(doneExp); 474 psFree(output); 475 return false; 476 } 477 478 psS64 exp_id = psDBLastInsertID(config->dbh); 479 480 // insert new pzDoneImfile into newImfile 481 { 482 char *query = 483 "INSERT INTO newImfile" 484 " SElECT" 485 " %" PRId64 "," // exp_id 486 " pzDoneImfile.class_id," // tmp_class_id 487 " pzDoneImfile.uri" // uri 488 " FROM pzDoneImfile" 489 " WHERE" 490 " pzDoneImfile.exp_name = '%s'" 491 " AND pzDoneImfile.camera = '%s'" 492 " AND pzDoneImfile.telescope = '%s'"; 493 494 if (!p_psDBRunQuery(config->dbh, query, exp_id, doneExp->exp_name, doneExp->camera, doneExp->telescope)) { 495 // rollback 496 if (!psDBRollback(config->dbh)) { 497 psError(PS_ERR_UNKNOWN, false, "database error"); 498 } 499 psError(PS_ERR_UNKNOWN, false, "database error"); 500 psFree(doneExp); 501 psFree(output); 502 return false; 503 } 504 505 // sanity check: we should have inserted only one row 506 psU64 affected = psDBAffectedRows(config->dbh); 507 if (psDBAffectedRows(config->dbh) != 1) { 508 // rollback 509 if (!psDBRollback(config->dbh)) { 510 psError(PS_ERR_UNKNOWN, false, "database error"); 511 } 512 psError(PS_ERR_UNKNOWN, false, "should have affected 1 row but %" PRIu64 " rows were modified", affected); 513 psFree(doneExp); 514 psFree(output); 515 return false; 516 } 517 } 518 519 psFree(doneExp); 520 } 521 522 psFree(output); 523 524 if (!psDBCommit(config->dbh)) { 525 psError(PS_ERR_UNKNOWN, false, "database error"); 526 return false; 527 } 528 529 return true; 530 }
Note:
See TracChangeset
for help on using the changeset viewer.
