Changeset 27838 for branches/tap_branches/ippTools/src/magicdstool.c
- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/magicdstool.c (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/ippTools/src
- Property svn:ignore
-
old new 16 16 difftool 17 17 disttool 18 dqstatstool 18 19 faketool 19 20 flatcorr
-
- Property svn:ignore
-
branches/tap_branches/ippTools/src/magicdstool.c
r25837 r27838 33 33 34 34 static bool definebyqueryMode(pxConfig *config); 35 static bool definecopyMode(pxConfig *config); 35 36 static bool updaterunMode(pxConfig *config); 36 37 static bool todestreakMode(pxConfig *config); … … 38 39 static bool advancerunMode(pxConfig *config); 39 40 static bool revertdestreakedfileMode(pxConfig *config); 41 static bool clearstatefaultsMode(pxConfig *config); 40 42 static bool getskycellsMode(pxConfig *config); 41 43 static bool toremoveMode(pxConfig *config); … … 44 46 static bool tocleanupMode(pxConfig *config); 45 47 46 static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, ps Metadata *where, const char *state);48 static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, psString extraSetString, psMetadata *where, const char *state); 47 49 48 50 # define MODECASE(caseName, func) \ … … 65 67 switch (config->mode) { 66 68 MODECASE(MAGICDSTOOL_MODE_DEFINEBYQUERY, definebyqueryMode); 69 MODECASE(MAGICDSTOOL_MODE_DEFINECOPY, definecopyMode); 67 70 MODECASE(MAGICDSTOOL_MODE_UPDATERUN, updaterunMode); 68 71 MODECASE(MAGICDSTOOL_MODE_TODESTREAK, todestreakMode); … … 70 73 MODECASE(MAGICDSTOOL_MODE_ADVANCERUN, advancerunMode); 71 74 MODECASE(MAGICDSTOOL_MODE_REVERTDESTREAKEDFILE,revertdestreakedfileMode); 75 MODECASE(MAGICDSTOOL_MODE_CLEARSTATEFAULTS, clearstatefaultsMode); 72 76 MODECASE(MAGICDSTOOL_MODE_GETSKYCELLS, getskycellsMode); 73 77 MODECASE(MAGICDSTOOL_MODE_TOREMOVE, toremoveMode); … … 110 114 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); 111 115 PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false); 112 PXOPT_LOOKUP_BOOL( dry_run, config->args, "-dry_run", false);116 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 113 117 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 114 118 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 124 128 PXOPT_COPY_S32(config->args, where, "-streaks_max","streaks", "<="); 125 129 126 pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "=="); 130 pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "=="); // define using magicRun label 127 131 128 132 ippStage stageNum = ippStringToStage(stage); 129 133 130 134 psString query = NULL; 131 135 switch (stageNum) { … … 147 151 case IPP_STAGE_FAKE: 148 152 case IPP_STAGE_STACK: 149 psError(PXTOOLS_ERR_ DATA, true, "%sRuns do not need to be destreaked", stage);153 psError(PXTOOLS_ERR_CONFIG, true, "%sRuns do not need to be destreaked", stage); 150 154 return false; 151 155 case IPP_STAGE_NONE: 152 psError(PXTOOLS_ERR_ DATA, true, "%s is not a valid stage", stage);156 psError(PXTOOLS_ERR_CONFIG, true, "%s is not a valid stage", stage); 153 157 return false; 154 158 default: … … 159 163 160 164 if (!query) { 161 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");165 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 162 166 return false; 163 167 } … … 233 237 // Parse the list of runs ready to be destreaked 234 238 235 if (! dry_run&& !psDBTransaction(config->dbh)) {239 if (!pretend && !psDBTransaction(config->dbh)) { 236 240 psError(PS_ERR_UNKNOWN, false, "database error"); 237 241 return false; … … 249 253 psString magicRunDataGroup = psMetadataLookupStr(NULL, row, "data_group"); 250 254 psString magicRunWorkdir = psMetadataLookupStr(NULL, row, "workdir"); 251 255 252 256 // if workdir is not supplied use the magicRun's 253 257 if (!workdir) { … … 282 286 } 283 287 284 if (! dry_run) {288 if (!pretend) { 285 289 if (!magicDSRunInsertObject(config->dbh, run)) { 286 290 psError(PS_ERR_UNKNOWN, false, "database error"); … … 301 305 } 302 306 303 if (! dry_run&& !psDBCommit(config->dbh)) {307 if (!pretend && !psDBCommit(config->dbh)) { 304 308 psError(PS_ERR_UNKNOWN, false, "database error"); 305 309 return false; … … 319 323 320 324 325 // XXX This currently allows multiple destreak runs to be queued on the same exposure if there are multiple 326 // magicRuns selected! 327 static bool definecopyMode(pxConfig *config) 328 { 329 // Required 330 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false); 331 PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false); 332 333 // Optional 334 PXOPT_LOOKUP_STR(recoveryroot, config->args, "-recoveryroot", false, false); 335 PXOPT_LOOKUP_BOOL(noreplace, config->args, "-noreplace", false); 336 PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false); 337 PXOPT_LOOKUP_STR(set_data_group, config->args, "-set_data_group", false, false); 338 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); 339 PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false); 340 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 341 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 342 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 343 344 // search args 345 psMetadata *where = psMetadataAlloc(); 346 PXOPT_COPY_S64(config->args, where, "-exp_id", "chipRun.exp_id", "=="); 347 PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "=="); 348 PXOPT_COPY_S64(config->args, where, "-cam_id", "camRun.cam_id", "=="); 349 PXOPT_COPY_S64(config->args, where, "-warp_id", "warpRun.warp_id", "=="); 350 PXOPT_COPY_S64(config->args, where, "-diff_id", "diffRun.diff_id", "=="); 351 PXOPT_COPY_S64(config->args, where, "-magic_id", "magicRun.magic_id", "=="); 352 PXOPT_COPY_S32(config->args, where, "-streaks_max", "magicMask.streaks", "<="); 353 354 pxAddLabelSearchArgs (config, where, "-magic_label", "magicRun.label", "=="); // define magic label 355 psString labelName = NULL; // Name of label 356 psStringAppend(&labelName, "%sRun.label", stage); 357 pxAddLabelSearchArgs (config, where, "-stage_label", labelName, "=="); // define stageRun label 358 psFree(labelName); 359 360 ippStage stageNum = ippStringToStage(stage); 361 362 psString query = NULL; 363 switch (stageNum) { 364 case IPP_STAGE_RAW: 365 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Raw stage is not appropriate for a copied destreak"); 366 return false; 367 case IPP_STAGE_CHIP: 368 query = pxDataGet("magicdstool_definecopy_chip.sql"); 369 break; 370 case IPP_STAGE_WARP: 371 query = pxDataGet("magicdstool_definecopy_warp.sql"); 372 break; 373 case IPP_STAGE_CAMERA: 374 case IPP_STAGE_DIFF: 375 case IPP_STAGE_FAKE: 376 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "%s has not been coded.", stage); 377 return false; 378 case IPP_STAGE_STACK: 379 psError(PXTOOLS_ERR_CONFIG, true, "Stacks do not need to be destreaked"); 380 return false; 381 case IPP_STAGE_NONE: 382 psError(PXTOOLS_ERR_CONFIG, true, "%s is not a valid stage", stage); 383 return false; 384 default: 385 psError(PXTOOLS_ERR_PROG, true, "ippStageToString returned %d for invalid stage %s", 386 stageNum, stage); 387 return false; 388 } 389 390 if (!query) { 391 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 392 return false; 393 } 394 const char *rerun_flag = rerun ? "" : "\n"; // String to give query to activate (or not) rerun 395 396 if (stageNum != IPP_STAGE_DIFF) { 397 if (psListLength(where->list)) { 398 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 399 psStringAppend(&query, "\nAND %s", whereClause); 400 psFree(whereClause); 401 } 402 psFree(where); 403 404 // treat limit == 0 as "no limit" 405 if (limit) { 406 psString limitString = psDBGenerateLimitSQL(limit); 407 psStringAppend(&query, " %s", limitString); 408 psFree(limitString); 409 } 410 if (!p_psDBRunQueryF(config->dbh, query, set_label, rerun_flag)) { 411 psError(PS_ERR_UNKNOWN, false, "database error"); 412 psFree(query); 413 return false; 414 } 415 } else { 416 // diff stage query has two types bothways and !bothways 417 // so we need to send the rerun flag and the where data twice 418 psString whereString = psStringCopy(""); 419 if (psListLength(where->list)) { 420 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 421 psStringAppend(&whereString, "\nAND %s", whereClause); 422 psFree(whereClause); 423 } 424 psFree(where); 425 426 // treat limit == 0 as "no limit" 427 if (limit) { 428 psString limitString = psDBGenerateLimitSQL(limit); 429 psStringAppend(&query, " %s", limitString); 430 psFree(limitString); 431 } 432 433 if (!p_psDBRunQueryF(config->dbh, query, rerun_flag, whereString, rerun_flag, whereString)) { 434 psError(PS_ERR_UNKNOWN, false, "database error"); 435 psFree(whereString); 436 psFree(query); 437 return false; 438 } 439 psFree(whereString); 440 } 441 psFree(query); 442 443 psArray *output = p_psDBFetchResult(config->dbh); 444 if (!output) { 445 psErrorCode err = psErrorCodeLast(); 446 switch (err) { 447 case PS_ERR_DB_CLIENT: 448 psError(PXTOOLS_ERR_SYS, false, "database error"); 449 case PS_ERR_DB_SERVER: 450 psError(PXTOOLS_ERR_PROG, false, "database error"); 451 default: 452 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 453 } 454 455 return false; 456 } 457 if (!psArrayLength(output)) { 458 psTrace("magictool", PS_LOG_INFO, "no rows found"); 459 psFree(output); 460 return true; 461 } 462 463 // Parse the list of runs ready to be destreaked 464 465 if (!pretend && !psDBTransaction(config->dbh)) { 466 psError(PS_ERR_UNKNOWN, false, "database error"); 467 return false; 468 } 469 470 psArray *list = psArrayAllocEmpty(16); // List of runs, to print 471 for (long i = 0; i < psArrayLength(output); i++) { 472 psMetadata *row = output->data[i]; // Row of interest 473 psS64 stage_id = psMetadataLookupS64(NULL, row, "stage_id"); 474 psS64 exp_id = psMetadataLookupS64(NULL, row, "exp_id"); 475 psS64 magic_id = psMetadataLookupS64(NULL, row, "magic_id"); 476 psS64 inv_magic_id = psMetadataLookupS64(NULL, row, "inv_magic_id"); 477 psS64 cam_id = psMetadataLookupS64(NULL, row, "cam_id"); 478 psString magicRunLabel = psMetadataLookupStr(NULL, row, "label"); 479 psString magicRunDataGroup = psMetadataLookupStr(NULL, row, "data_group"); 480 481 psString outroot = NULL; 482 // set outroot to workdir/exp_id/stage for example /somewhere/424242/chip 483 psStringAppend(&outroot, "%s/%" PRId64 "/%s", workdir, exp_id, stage); 484 485 // create a new magicRun for this group 486 magicDSRunRow *run = magicDSRunRowAlloc( 487 0, // magic_ds_id 488 magic_id, 489 inv_magic_id, 490 "new", 491 stage, 492 stage_id, 493 cam_id, 494 set_label ? set_label : magicRunLabel, 495 set_data_group ? set_data_group : magicRunDataGroup, 496 outroot, 497 recoveryroot, 498 noreplace ? 0 :1, // re_place 499 0, // remove 500 0, // fault 501 note); // remove 502 503 psFree(outroot); 504 if (!run) { 505 psAbort("failed to alloc magicDSRun object"); 506 } 507 508 if (!pretend) { 509 if (!magicDSRunInsertObject(config->dbh, run)) { 510 psError(PS_ERR_UNKNOWN, false, "database error"); 511 psFree(run); 512 psFree(output); 513 psFree(list); 514 if (!psDBRollback(config->dbh)) { 515 psError(PS_ERR_UNKNOWN, false, "database error"); 516 } 517 return false; 518 } 519 psS64 magic_ds_id = psDBLastInsertID(config->dbh); // Assigned identifier 520 run->magic_ds_id = magic_ds_id; 521 } 522 523 psArrayAdd(list, list->n, run); 524 psFree(run); 525 } 526 527 if (!pretend && !psDBCommit(config->dbh)) { 528 psError(PS_ERR_UNKNOWN, false, "database error"); 529 return false; 530 } 531 psFree(output); 532 533 if (!magicDSRunPrintObjects(stdout, list, !simple)) { 534 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 535 psFree(list); 536 return false; 537 } 538 539 psFree(list); 540 541 return true; 542 } 543 544 321 545 static bool updaterunMode(pxConfig *config) 322 546 { … … 326 550 PXOPT_LOOKUP_STR(state, config->args, "-set_state", true, false); 327 551 552 // optional 553 PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false); 554 PXOPT_LOOKUP_STR(set_data_group, config->args, "-set_data_group", false, false); 555 psString setString = NULL; 556 if (set_label) { 557 psStringAppend(&setString, ", label = '%s'", set_label); 558 } 559 if (set_data_group) { 560 psStringAppend(&setString, ", data_group = '%s'", set_data_group); 561 } 562 328 563 PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", false, false); 329 564 if (magic_ds_id) { 330 565 331 return setmagicDSRunState(config, magic_ds_id, NULL, state);566 return setmagicDSRunState(config, magic_ds_id, setString, NULL, state); 332 567 333 568 } else if (!strcmp(state, "full")) { … … 341 576 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); 342 577 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 343 578 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 579 PXOPT_COPY_STR(config->args, where, "-data_group", "data_group", "LIKE"); 344 580 345 581 if (psListLength(where->list) < 2) { … … 353 589 psMetadataAddS32(where, PS_LIST_TAIL, "re_place", 0, ">", 0); 354 590 } 355 bool result = setmagicDSRunState(config, magic_ds_id, where, state);591 bool result = setmagicDSRunState(config, magic_ds_id, setString, where, state); 356 592 psFree(where); 357 593 … … 379 615 psString query = pxDataGet(sql_file); 380 616 if (!query) { 381 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement from %s", sql_file);617 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement from %s", sql_file); 382 618 psFree(sql_file); 383 619 return false; … … 445 681 { 446 682 // first query the magicDSRun to find the stage and the stage_id 447 psString query = "SELECT stage, stage_id from magicDSRun where magic_ds_id = %" PRId64;683 psString query = "SELECT stage, stage_id, magic_id from magicDSRun where magic_ds_id = %" PRId64; 448 684 449 685 if (!p_psDBRunQueryF(config->dbh, query, magic_ds_id)) { … … 472 708 psString stage= psMetadataLookupStr(NULL, row, "stage"); 473 709 psS64 stage_id = psMetadataLookupS64(NULL, row, "stage_id"); 710 psS64 magic_id = psMetadataLookupS64(NULL, row, "magic_id"); 474 711 475 712 ippStage stageNum = ippStringToStage(stage); … … 499 736 } 500 737 501 if (!p_psDBRunQueryF(config->dbh, query, magic_ ds_id, stage_id, component)) {738 if (!p_psDBRunQueryF(config->dbh, query, magic_id, stage_id, component)) { 502 739 psError(PS_ERR_UNKNOWN, false, "database error"); 503 740 return false; … … 518 755 { 519 756 // first query the magicDSRun to find the stage and the stage_id 520 psString query = "SELECT stage, stage_id from magicDSRun where magic_ds_id = %" PRId64;757 psString query = "SELECT stage, stage_id, magic_id from magicDSRun where magic_ds_id = %" PRId64; 521 758 522 759 if (!p_psDBRunQueryF(config->dbh, query, magic_ds_id)) { … … 545 782 psString stage = psMetadataLookupStr(NULL, row, "stage"); 546 783 psS64 stage_id = psMetadataLookupS64(NULL, row, "stage_id"); 784 psS64 magic_id = psMetadataLookupS64(NULL, row, "magic_id"); 547 785 548 786 ippStage stageNum = ippStringToStage(stage); … … 570 808 return false; 571 809 } 572 if (!p_psDBRunQueryF(config->dbh, query, magic_ ds_id, stage_id)) {810 if (!p_psDBRunQueryF(config->dbh, query, magic_id, stage_id)) { 573 811 psError(PS_ERR_UNKNOWN, false, "database error"); 574 812 return false; … … 598 836 PXOPT_LOOKUP_STR(recovery_path_base, config->args, "-recovery_path_base", false, false); 599 837 PXOPT_LOOKUP_BOOL(setmagicked, config->args, "-setmagicked", false); 838 PXOPT_LOOKUP_F32(streak_frac, config->args, "-streak_frac", false, false); 839 PXOPT_LOOKUP_F32(nondiff_frac, config->args, "-nondiff_frac", false, false); 840 PXOPT_LOOKUP_F32(run_time, config->args, "-run_time", false, false); 600 841 601 842 if (setmagicked && (fault != 0)) { … … 620 861 } 621 862 622 if (!magicDSFileInsert(config->dbh, magic_ds_id, component, backup_path_base, recovery_path_base, fault, "full")) { 863 if (!magicDSFileInsert(config->dbh, 864 magic_ds_id, 865 component, 866 backup_path_base, 867 recovery_path_base, 868 streak_frac, 869 nondiff_frac, 870 run_time, 871 fault, 872 "full" // data_state 873 )) { 623 874 // rollback 624 875 if (!psDBRollback(config->dbh)) { … … 651 902 psString query = pxDataGet("magicdstool_completed_runs.sql"); 652 903 if (!query) { 653 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");904 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 654 905 return false; 655 906 } … … 699 950 700 951 // set magicDSRun.state to 'full' 701 if (!setmagicDSRunState(config, magic_ds_id, NULL, "full")) {952 if (!setmagicDSRunState(config, magic_ds_id, NULL, NULL, "full")) { 702 953 psError(PS_ERR_UNKNOWN, false, "failed to change magicDSRun.state for magic_ds_id: %" PRId64, 703 954 magic_ds_id); … … 747 998 748 999 if (!p_psDBRunQuery(config->dbh, query)) { 1000 psError(PS_ERR_UNKNOWN, false, "failed to revert"); 1001 psFree(query); 1002 return false; 1003 } 1004 psFree(query); 1005 return true; 1006 } 1007 static bool clearstatefaultsMode(pxConfig *config) 1008 { 1009 PS_ASSERT_PTR_NON_NULL(config, false); 1010 1011 psMetadata *where = psMetadataAlloc(); 1012 // new state 1013 PXOPT_LOOKUP_STR(new_state, config->args, "-set_state", false, false); 1014 // old state (required) 1015 PXOPT_LOOKUP_STR(state, config->args, "-state", true, false); 1016 1017 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 1018 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magicDSRun.magic_ds_id", "=="); 1019 PXOPT_COPY_S16(config->args, where, "-fault", "fault", "=="); 1020 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 1021 1022 psString query = pxDataGet("magicdstool_clearstatefaults.sql"); 1023 1024 if (psListLength(where->list)) { 1025 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1026 psStringAppend(&query, " WHERE %s", whereClause); 1027 psFree(whereClause); 1028 } else { 1029 psError(PS_ERR_UNKNOWN, true, "search arguments are required"); 1030 return false; 1031 } 1032 psFree(where); 1033 1034 if (!new_state) { 1035 if (!strcmp(state, "failed_revert")) { 1036 new_state = "new"; 1037 } else if (!strcmp(state, "failed_cleanup")) { 1038 new_state = "goto_cleaned"; 1039 } else { 1040 psError(PS_ERR_UNKNOWN, true, "unexpected value for state: %s", state); 1041 return false; 1042 } 1043 } 1044 if (!p_psDBRunQueryF(config->dbh, query, new_state)) { 749 1045 psError(PS_ERR_UNKNOWN, false, "failed to revert"); 750 1046 psFree(query); … … 809 1105 for (int i=0; i<psArrayLength(output); i++) { 810 1106 psMetadata *row = output->data[i]; 811 psS64 magic_ds_id = psMetadataLookupS64(NULL, row, "magic_ds_id"); 812 psString old_state = psMetadataLookupStr(NULL, row, "state"); 1107 psS64 magic_ds_id = psMetadataLookupS64(NULL, row, "magic_ds_id"); 1108 psString old_state = psMetadataLookupStr(NULL, row, "state"); 813 1109 psString new_state; 814 1110 if (!strcmp(old_state, "goto_censored")) { … … 838 1134 839 1135 psMetadata *where = psMetadataAlloc(); 1136 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magicDSRun.magic_ds_id", "=="); 840 1137 PXOPT_COPY_STR(config->args, where, "-class_id", "warpSkyCellMap.class_id", "=="); 841 1138 PXOPT_COPY_STR(config->args, where, "-skycell_id", "warpSkyCellMap.skycell_id", "=="); … … 845 1142 psString query = pxDataGet("magicdstool_getskycells.sql"); 846 1143 if (!query) { 847 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 848 return false; 849 } 850 1144 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1145 return false; 1146 } 1147 1148 psString whereClause = NULL; 851 1149 if (psListLength(where->list)) { 852 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 853 psStringAppend(&query, " AND %s", whereClause); 854 psFree(whereClause); 1150 whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1151 psStringPrepend(&whereClause, "\n AND "); 855 1152 } 856 1153 psFree(where); 857 1154 858 if (!p_psDBRunQueryF(config->dbh, query, magic_ds_id)) {1155 if (!p_psDBRunQueryF(config->dbh, query, whereClause, whereClause)) { 859 1156 psError(PS_ERR_UNKNOWN, false, "database error"); 860 1157 psFree(query); … … 901 1198 if (!((strcmp(state, "new") == 0) || 902 1199 (strcmp(state, "full") == 0) || 1200 (strcmp(state, "drop") == 0) || 1201 (strcmp(state, "failed_revert") == 0) || 1202 (strcmp(state, "failed_cleanup") == 0) || 903 1203 (strcmp(state, "restored") == 0) || 904 1204 (strcmp(state, "censored") == 0) || … … 914 1214 } 915 1215 916 static bool setmagicDSRunState(pxConfig *config, psS64 magic_ds_id, ps Metadata *where, const char *state)1216 static bool setmagicDSRunState(pxConfig *config, psS64 magic_ds_id, psString extraSetStr, psMetadata *where, const char *state) 917 1217 { 918 1218 PS_ASSERT_PTR_NON_NULL(state, false); … … 924 1224 } 925 1225 926 psString query = psStringCopy("UPDATE magicDSRun SET state = '%s'"); 1226 psString query = NULL; 1227 psStringAppend(&query, "UPDATE magicDSRun SET state = '%s' %s\n", state, extraSetStr ? extraSetStr : ""); 927 1228 if (magic_ds_id) { 928 1229 psStringAppend(&query, " WHERE magic_ds_id = %" PRId64, magic_ds_id); … … 932 1233 psFree(whereClause); 933 1234 } else { 934 psError(PS_ERR_UNKNOWN, true, "search arugments are required"); 935 return false; 936 } 937 938 if (!p_psDBRunQueryF(config->dbh, query, state)) { 1235 psError(PS_ERR_UNKNOWN, true, "search arguments are required"); 1236 return false; 1237 } 1238 1239 if (!strcmp(state, "goto_cleaned")) { 1240 // Don't set state back to goto_cleaned if it is already cleaned 1241 psStringAppend(&query, " AND (magicDSRun.state != 'cleaned')"); 1242 1243 // don't clean up magicDSRun's where stage is camera 1244 psStringAppend(&query, " AND (magicDSRun.stage != 'camera')"); 1245 } 1246 1247 if (!p_psDBRunQuery(config->dbh, query)) { 939 1248 psError(PS_ERR_UNKNOWN, false, 940 1249 "failed to change state for magic_id %" PRId64, magic_ds_id); … … 960 1269 psString query = pxDataGet("magicdstool_toremove.sql"); 961 1270 if (!query) { 962 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1271 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 963 1272 return false; 964 1273 } … … 1038 1347 psString query = pxDataGet(sql_file); 1039 1348 if (!query) { 1040 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement from %s", sql_file);1349 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement from %s", sql_file); 1041 1350 psFree(sql_file); 1042 1351 return false; … … 1106 1415 psMetadata *where = psMetadataAlloc(); 1107 1416 1108 PXOPT_COPY_S 64(config->args, where, "-stage", "stage", "==");1417 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 1109 1418 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "=="); 1110 1419 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); … … 1116 1425 psString query = pxDataGet("magicdstool_tocleanup.sql"); 1117 1426 if (!query) { 1118 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1427 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1119 1428 return false; 1120 1429 }
Note:
See TracChangeset
for help on using the changeset viewer.
