Changeset 30671 for trunk/ippTools/src
- Timestamp:
- Feb 17, 2011, 11:28:02 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/magicdstool.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/magicdstool.c
r30548 r30671 709 709 710 710 711 // update the magicked column for the underlying component 712 // Note: Must be called inside a transaction 713 711 714 static bool 712 setMagicked(pxConfig *config, psS64 magic_ds_id, psString component )715 setMagicked(pxConfig *config, psS64 magic_ds_id, psString component, bool clearMagicked) 713 716 { 714 717 // first query the magicDSRun to find the stage and the stage_id … … 741 744 psS64 stage_id = psMetadataLookupS64(NULL, row, "stage_id"); 742 745 psS64 magic_id = psMetadataLookupS64(NULL, row, "magic_id"); 746 psFree(output); 747 748 psS64 newMagickedValue; 749 if (clearMagicked) { 750 newMagickedValue = 0; 751 } else { 752 newMagickedValue = magic_id; 753 } 743 754 744 755 ippStage stageNum = ippStringToStage(stage); 745 756 746 757 // chose the appropriate query based on the stage 758 char *clearRunQuery = NULL; 747 759 switch (stageNum) { 748 760 case IPP_STAGE_RAW: 749 761 query = "UPDATE rawImfile SET magicked = %" PRId64 " where exp_id = %" PRId64 " AND class_id = '%s'"; 762 clearRunQuery = "UPDATE rawExp SET magicked = 0 where exp_id = %" PRId64; 750 763 break; 751 764 case IPP_STAGE_CHIP: 752 765 query = "UPDATE chipProcessedImfile SET magicked = %" PRId64 " where chip_id = %" PRId64 " AND class_id = '%s'"; 766 clearRunQuery = "UPDATE chipRun set magicked = 0 where chip_id = %" PRId64; 753 767 break; 754 768 case IPP_STAGE_CHIP_BG: 755 769 query = "UPDATE chipBackgroundImfile SET magicked = %" PRId64 " where chip_bg_id = %" PRId64 " AND class_id = '%s'"; 770 clearRunQuery = "UPDATE chipBackgroundRun SET magicked = 0 where chip_bg_id = %" PRId64; 756 771 break; 757 772 case IPP_STAGE_CAMERA: 758 // no there is no magicked column in camProcessedExp so we have nothing to do 759 psFree(output); 760 return true; 773 psFree(query); 774 query = NULL; 775 clearRunQuery = "UPDATE chipBackgroundRun SET magicked = 0 where chip_bg_id = %" PRId64; 776 break; 761 777 case IPP_STAGE_WARP: 762 778 query = "UPDATE warpSkyfile SET magicked = %" PRId64 " where warp_id = %" PRId64 " AND skycell_id = '%s'"; 779 clearRunQuery = "UPDATE warpRun SET magicked = 0 where warp_id = %" PRId64; 763 780 break; 764 781 case IPP_STAGE_WARP_BG: 765 782 query = "UPDATE warpBackgroundSkyfile SET magicked = %" PRId64 " where warp_bg_id = %" PRId64 " AND skycell_id = '%s'"; 783 clearRunQuery = "UPDATE warpBackgroundRun SET magicked = 0 where warp_bg_id = %" PRId64; 766 784 break; 767 785 case IPP_STAGE_DIFF: 768 786 query = "UPDATE diffSkyfile SET magicked = %" PRId64 " where diff_id = %" PRId64 " AND skycell_id = '%s'"; 787 clearRunQuery = "UPDATE diffRun SET magicked = 0 where diff_id = %" PRId64; 769 788 break; 770 789 default: 771 790 psError(PS_ERR_UNKNOWN, true, "unexpected value for stage: %s found", stage); 772 psFree(output); 773 return false; 774 } 775 776 if (!p_psDBRunQueryF(config->dbh, query, magic_id, stage_id, component)) { 777 psError(PS_ERR_UNKNOWN, false, "database error"); 778 return false; 779 } 780 psFree(output); 781 782 psU64 affected = psDBAffectedRows(config->dbh); 783 if (affected != 1) { 784 psError(PS_ERR_UNKNOWN, false, "should have affected 1 row"); 785 return false; 791 return false; 792 } 793 794 if (query) { 795 if (!p_psDBRunQueryF(config->dbh, query, newMagickedValue, stage_id, component)) { 796 psError(PS_ERR_UNKNOWN, false, "database error"); 797 return false; 798 } 799 } 800 801 if (clearMagicked && clearRunQuery) { 802 if (!p_psDBRunQueryF(config->dbh, clearRunQuery, stage_id)) { 803 psError(PS_ERR_UNKNOWN, false, "database error"); 804 return false; 805 } 786 806 } 787 807 … … 896 916 if (setmagicked) { 897 917 // set the image file's magicked flag 898 if (!setMagicked(config, magic_ds_id, component )) {918 if (!setMagicked(config, magic_ds_id, component, false)) { 899 919 psError(PS_ERR_UNKNOWN, false, "setMagicked failed"); 900 920 if (!psDBRollback(config->dbh)) { … … 1111 1131 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 1112 1132 1133 PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false); 1134 PXOPT_LOOKUP_STR(component, config->args, "-component", true, false); 1113 1135 PXOPT_LOOKUP_STR(state, config->args, "-state", false, false); 1114 1136 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); … … 1116 1138 psString queryFile = NULL; 1117 1139 bool stateIsUpdate = false; 1140 bool toRestored = !strcmp(state, "goto_restored"); 1118 1141 if (state) { 1119 if (! strcmp(state, "new") || !strcmp(state, "goto_restored")) {1142 if (! strcmp(state, "new") || toRestored) { 1120 1143 queryFile = "magicdstool_revertdestreakedfile.sql"; 1121 1144 } else if (!strcmp(state, "update")) { … … 1153 1176 } 1154 1177 1178 if (!psDBTransaction(config->dbh)) { 1179 psError(PS_ERR_UNKNOWN, false, "database error"); 1180 return false; 1181 } 1155 1182 if (!p_psDBRunQuery(config->dbh, query)) { 1156 1183 psError(PS_ERR_UNKNOWN, false, "failed to revert"); … … 1159 1186 } 1160 1187 psFree(query); 1188 if (toRestored) { 1189 // clear the underlying component's magicked value 1190 if (!setMagicked(config, magic_ds_id, component, true)) { 1191 psError(PS_ERR_UNKNOWN, false, "setMagicked failed"); 1192 if (!psDBRollback(config->dbh)) { 1193 psError(PS_ERR_UNKNOWN, false, "database error"); 1194 } 1195 return false; 1196 } 1197 } 1198 if (!psDBCommit(config->dbh)) { 1199 psError(PS_ERR_UNKNOWN, false, "database error"); 1200 return false; 1201 } 1161 1202 return true; 1162 1203 } … … 1661 1702 } 1662 1703 if (!strcmp(data_state, "full")) { 1663 // if -tofullfile optoinally set the magicked value for the component 1664 PXOPT_LOOKUP_BOOL(setmagicked, config->args, "-setmagicked", false); 1665 // set the image file's magicked flag 1666 if (!setMagicked(config, magic_ds_id, component)) { 1704 // set the component's magicked flag 1705 1706 if (!setMagicked(config, magic_ds_id, component, false)) { 1667 1707 psError(PS_ERR_UNKNOWN, false, "setMagicked failed"); 1668 1708 if (!psDBRollback(config->dbh)) { … … 1716 1756 return change_file_data_state(config, "full"); 1717 1757 } 1718 /*1719 static bool topurgedimfileMode(pxConfig *config)1720 {1721 return change_imfile_data_state(config, "purged", "goto_purged");1722 }1723 static bool toscrubbedfileMode(pxConfig *config)1724 {1725 return change_file_data_state(config, "scrubbed", "goto_scrubbed");1726 }1727 */1728 1758 1729 1759 // a very specfic function to queue a cleaned magicDSFile to be updated
Note:
See TracChangeset
for help on using the changeset viewer.
