- Timestamp:
- Mar 30, 2012, 2:49:37 PM (14 years ago)
- Location:
- branches/eam_branches/ipp-20111122/ippTools/src
- Files:
-
- 2 edited
-
. (modified) (2 props)
-
staticskytool.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/ippTools/src
- Property svn:ignore
-
old new 7 7 Makefile.in 8 8 addtool 9 mergetool 9 10 caltool 10 11 camtool
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/eam_branches/ipp-20111122/ippTools/src/staticskytool.c
r31690 r33638 38 38 static bool resultMode(pxConfig *config); 39 39 static bool revertMode(pxConfig *config); 40 static bool updateresult (pxConfig *config);40 static bool updateresultMode(pxConfig *config); 41 41 static bool exportrunMode(pxConfig *config); 42 42 static bool importrunMode(pxConfig *config); 43 44 static bool defineskycalrunMode(pxConfig *config); 45 static bool updateskycalrunMode(pxConfig *config); 46 static bool pendingskycalrunMode(pxConfig *config); 47 static bool addskycalresultMode(pxConfig *config); 48 static bool skycalresultMode(pxConfig *config); 49 static bool revertskycalresultMode(pxConfig *config); 50 static bool updateskycalresultMode(pxConfig *config); 43 51 44 52 static bool setstaticskyRunState(pxConfig *config, psS64 sky_id, const char *state); … … 69 77 MODECASE(STATICSKYTOOL_MODE_RESULT, resultMode); 70 78 MODECASE(STATICSKYTOOL_MODE_REVERT, revertMode); 71 MODECASE(STATICSKYTOOL_MODE_UPDATERESULT, updateresult );79 MODECASE(STATICSKYTOOL_MODE_UPDATERESULT, updateresultMode); 72 80 MODECASE(STATICSKYTOOL_MODE_EXPORTRUN, exportrunMode); 73 81 MODECASE(STATICSKYTOOL_MODE_IMPORTRUN, importrunMode); 82 MODECASE(STATICSKYTOOL_MODE_DEFINESKYCALRUN, defineskycalrunMode); 83 MODECASE(STATICSKYTOOL_MODE_UPDATESKYCALRUN, updateskycalrunMode); 84 MODECASE(STATICSKYTOOL_MODE_PENDINGSKYCALRUN, pendingskycalrunMode); 85 MODECASE(STATICSKYTOOL_MODE_ADDSKYCALRESULT, addskycalresultMode); 86 MODECASE(STATICSKYTOOL_MODE_UPDATESKYCALRESULT,updateskycalresultMode); 87 MODECASE(STATICSKYTOOL_MODE_REVERTSKYCALRESULT,revertskycalresultMode); 88 MODECASE(STATICSKYTOOL_MODE_SKYCALRESULT, skycalresultMode); 74 89 default: 75 90 psAbort("invalid option (this should not happen)"); … … 97 112 { 98 113 PS_ASSERT_PTR_NON_NULL(config, false); 99 100 // required options 101 PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false); 114 PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false); 115 PXOPT_LOOKUP_STR(label, config->args, "-set_label", true, false); 102 116 103 117 // optional 104 PXOPT_LOOKUP_STR(label, config->args, "-set_label", true, false);105 118 PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false); 106 119 PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false); … … 111 124 psMetadata *whereMD = psMetadataAlloc(); 112 125 113 PXOPT_COPY_STR(config->args, whereMD, "-select_skycell_id", "stackRun.skycell_id", "=="); 126 PXOPT_COPY_S64(config->args, whereMD, "-select_stack_id", "stackRun.stack_id", "=="); 127 PXOPT_COPY_STR(config->args, whereMD, "-select_skycell_id", "stackRun.skycell_id", "LIKE"); 114 128 PXOPT_COPY_STR(config->args, whereMD, "-select_tess_id", "stackRun.tess_id", "=="); 115 129 PXOPT_COPY_F32(config->args, whereMD, "-select_good_frac_min", "stackSumSkyfile.good_frac", ">="); … … 621 635 PXOPT_COPY_STR(config->args, where, "-label", "staticskyRun.label", "=="); 622 636 PXOPT_COPY_STR(config->args, where, "-data_group", "staticskyRun.data_group", "LIKE"); 637 PXOPT_COPY_STR(config->args, where, "-tess_id", "stackRun.tess_id", "LIKE"); 638 PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "LIKE"); 623 639 PXOPT_COPY_S16(config->args, where, "-fault", "staticskyResult.fault", "=="); 640 PXOPT_LOOKUP_S32(num_filters, config->args, "-num_filters", false, false); 624 641 625 642 PXOPT_LOOKUP_BOOL(all, config->args, "-all", false); … … 645 662 psFree(where); 646 663 664 psStringAppend(&query, "\nGROUP BY sky_id"); 665 if (num_filters) { 666 psStringAppend(&query, "\nHAVING COUNT(filter) >= %d", num_filters); 667 } 668 669 647 670 // treat limit == 0 as "no limit" 648 671 if (limit) { 649 672 psString limitString = psDBGenerateLimitSQL(limit); 650 psStringAppend(&query, " %s", limitString);673 psStringAppend(&query, "\n%s", limitString); 651 674 psFree(limitString); 652 675 } … … 735 758 } 736 759 737 static bool updateresult (pxConfig *config)760 static bool updateresultMode(pxConfig *config) 738 761 { 739 762 PS_ASSERT_PTR_NON_NULL(config, false); … … 978 1001 # endif 979 1002 1003 static bool defineskycalrunMode(pxConfig *config) 1004 { 1005 PS_ASSERT_PTR_NON_NULL(config, false); 1006 1007 // required options 1008 // none required. We get workdir, etc from staticskyRun if not provided 1009 1010 // optional 1011 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); 1012 PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", false, false); 1013 PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false); 1014 PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false); 1015 PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false); 1016 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); 1017 PXOPT_LOOKUP_TIME(registered, config->args, "-set_registered", false, false); 1018 1019 psMetadata *whereMD = psMetadataAlloc(); 1020 1021 PXOPT_COPY_S64(config->args, whereMD, "-select_sky_id", "staticskyRun.sky_id", "=="); 1022 PXOPT_COPY_S64(config->args, whereMD, "-select_stack_id", "stackRun.stack_id", "=="); 1023 PXOPT_COPY_STR(config->args, whereMD, "-select_skycell_id", "stackRun.skycell_id", "=="); 1024 PXOPT_COPY_STR(config->args, whereMD, "-select_tess_id", "stackRun.tess_id", "=="); 1025 PXOPT_COPY_F32(config->args, whereMD, "-select_good_frac_min", "stackSumSkyfile.good_frac", ">="); 1026 pxAddLabelSearchArgs(config, whereMD, "-select_label", "stackRun.label", "LIKE"); 1027 pxAddLabelSearchArgs(config, whereMD, "-select_data_group", "stackRun.data_group", "LIKE"); 1028 pxAddLabelSearchArgs(config, whereMD, "-select_filter", "stackRun.filter", "LIKE"); 1029 1030 PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false); 1031 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1032 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 1033 1034 psString query = pxDataGet("staticskytool_defineskycalrun.sql"); 1035 if (!query) { 1036 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1037 psFree(whereMD); 1038 return false; 1039 } 1040 1041 if (!psListLength(whereMD->list)) { 1042 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1043 psFree(whereMD); 1044 return false; 1045 } 1046 1047 psString whereClause = psDBGenerateWhereConditionSQL(whereMD, NULL); 1048 psStringAppend(&query, "\nAND %s", whereClause); 1049 psFree(whereClause); 1050 psFree(whereMD); 1051 1052 if (!rerun) { 1053 if (label) { 1054 psStringAppend(&query, "\nAND (skycalRun.label IS NULL OR skycalRun.label = '%s')", label); 1055 } 1056 psStringAppend(&query, "\nAND skycal_id IS NULL"); 1057 } 1058 1059 if (!p_psDBRunQuery(config->dbh, query)) { 1060 psError(PS_ERR_UNKNOWN, false, "database error"); 1061 psFree(query); 1062 return false; 1063 } 1064 psFree(query); 1065 1066 // we now have a list of (tess_id, skycell_id) that (potentially) meet out needs 1067 // we now need to loop over all of these and for each pair, select the best set of 1068 // inputs 1069 1070 psArray *output = p_psDBFetchResult(config->dbh); 1071 if (!output) { 1072 psErrorCode err = psErrorCodeLast(); 1073 switch (err) { 1074 case PS_ERR_DB_CLIENT: 1075 psError(PXTOOLS_ERR_SYS, false, "database error"); 1076 case PS_ERR_DB_SERVER: 1077 psError(PXTOOLS_ERR_PROG, false, "database error"); 1078 default: 1079 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1080 } 1081 return false; 1082 } 1083 if (!psArrayLength(output)) { 1084 psWarning("staticskytool: no rows found"); 1085 psFree(output); 1086 return true; 1087 } 1088 if (pretend) { 1089 // negative simple so the default is true 1090 if (!ippdbPrintMetadatas(stdout, output, "skycalRun", !simple)) { 1091 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1092 psFree(output); 1093 return false; 1094 } 1095 psFree(output); 1096 return true; 1097 } 1098 1099 for (long i = 0; i < output->n; i++) { 1100 psMetadata *row = output->data[i]; // Row from select 1101 bool status; 1102 1103 psS64 sky_id = psMetadataLookupS64(&status, row, "sky_id"); 1104 psS64 stack_id = psMetadataLookupS64(&status, row, "stack_id"); 1105 psString sky_workdir = psMetadataLookupStr(&status, row, "workdir"); 1106 psString sky_label = psMetadataLookupStr(&status, row, "label"); 1107 psString sky_data_group = psMetadataLookupStr(&status, row, "data_group"); 1108 1109 // create a staticskyRun 1110 if (!skycalRunInsert(config->dbh, 1111 0x0, // skycal_id 1112 sky_id, 1113 stack_id, 1114 "new", // state 1115 workdir ? workdir : sky_workdir, 1116 label ? label : sky_label, 1117 data_group ? data_group : sky_data_group, 1118 dist_group, 1119 reduction, 1120 registered, 1121 note 1122 ) 1123 ) { 1124 psError(PS_ERR_UNKNOWN, false, "database error"); 1125 psFree(output); 1126 return false; 1127 } 1128 1129 } 1130 psFree(output); 1131 return true; 1132 } 1133 1134 static bool updateskycalrunMode(pxConfig *config) 1135 { 1136 #ifdef notyet 1137 PS_ASSERT_PTR_NON_NULL(config, false); 1138 1139 psMetadata *where = psMetadataAlloc(); 1140 PXOPT_COPY_S64(config->args, where, "-sky_id", "sky_id", "=="); 1141 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 1142 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 1143 if (!psListLength(where->list)) { 1144 psFree(where); 1145 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1146 return false; 1147 } 1148 1149 psString query = psStringCopy("UPDATE staticskyRun"); 1150 1151 // pxUpdateRun gets parameters from config->args and updates 1152 bool result = pxUpdateRun(config, where, &query, "staticskyRun", "sky_id", "staticskyResult", true, false); 1153 psFree(query); 1154 psFree(where); 1155 1156 return result; 1157 #endif 1158 return false; 1159 } 1160 static bool pendingskycalrunMode(pxConfig *config) 1161 { 1162 PS_ASSERT_PTR_NON_NULL(config, false); 1163 1164 psMetadata *whereMD = psMetadataAlloc(); 1165 PXOPT_COPY_S64(config->args, whereMD, "-skycal_id", "skycal_id", "=="); 1166 PXOPT_COPY_S64(config->args, whereMD, "-sky_id", "sky_id", "=="); 1167 pxAddLabelSearchArgs (config, whereMD, "-label", "skycalRun.label", "=="); 1168 PXOPT_COPY_STR(config->args, whereMD, "-filter", "stackRun.filter", "LIKE"); 1169 1170 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1171 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1172 1173 psString query = pxDataGet("staticskytool_pendingskycalrun.sql"); 1174 if (!query) { 1175 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1176 return false; 1177 } 1178 1179 if (!psListLength(whereMD->list)) { 1180 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1181 psFree(whereMD); 1182 return false; 1183 } 1184 1185 psString whereClause = psDBGenerateWhereConditionSQL(whereMD, NULL); 1186 psStringAppend(&query, "\n AND %s", whereClause); 1187 psFree(whereClause); 1188 psFree(whereMD); 1189 1190 // treat limit == 0 as "no limit" 1191 if (limit) { 1192 psString limitString = psDBGenerateLimitSQL(limit); 1193 psStringAppend(&query, "\n%s", limitString); 1194 psFree(limitString); 1195 } 1196 1197 // the where clause is required and matches the WHERE hook format string 1198 if (!p_psDBRunQuery(config->dbh, query)) { 1199 psError(PS_ERR_UNKNOWN, false, "database error"); 1200 psFree(query); 1201 return false; 1202 } 1203 psFree(query); 1204 1205 psArray *output = p_psDBFetchResult(config->dbh); 1206 if (!output) { 1207 psErrorCode err = psErrorCodeLast(); 1208 switch (err) { 1209 case PS_ERR_DB_CLIENT: 1210 psError(PXTOOLS_ERR_SYS, false, "database error"); 1211 case PS_ERR_DB_SERVER: 1212 psError(PXTOOLS_ERR_PROG, false, "database error"); 1213 default: 1214 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1215 } 1216 1217 return false; 1218 } 1219 if (!psArrayLength(output)) { 1220 psTrace("staticskytool", PS_LOG_INFO, "no rows found"); 1221 psFree(output); 1222 return true; 1223 } 1224 1225 if (psArrayLength(output)) { 1226 // negative simple so the default is true 1227 if (!ippdbPrintMetadatas(stdout, output, "pendingskycalRun", !simple)) { 1228 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1229 psFree(output); 1230 return false; 1231 } 1232 } 1233 1234 psFree(output); 1235 return true; 1236 } 1237 1238 static bool addskycalresultMode(pxConfig *config) 1239 { 1240 PS_ASSERT_PTR_NON_NULL(config, false); 1241 1242 // required 1243 PXOPT_LOOKUP_S64(skycal_id, config->args, "-skycal_id", true, false); 1244 1245 // optional 1246 PXOPT_LOOKUP_F32(sigma_ra, config->args, "-sigma_ra", false, false); 1247 PXOPT_LOOKUP_F32(sigma_dec, config->args, "-sigma_dec", false, false); 1248 1249 PXOPT_LOOKUP_F32(zpt_obs, config->args, "-zpt_obs", false, false); 1250 PXOPT_LOOKUP_F32(zpt_stdev, config->args, "-zpt_stdev", false, false); 1251 1252 1253 PXOPT_LOOKUP_F32(dtime_script, config->args, "-dtime_script", false, false); 1254 PXOPT_LOOKUP_F32(dtime_astrom, config->args, "-dtime_astrom", false, false); 1255 1256 PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false); 1257 // PXOPT_LOOKUP_S32(n_stars, config->args, "-n_stars", false, false); 1258 PXOPT_LOOKUP_S32(n_astrom, config->args, "-n_astrom", false, false); 1259 1260 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false); 1261 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 1262 PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false); 1263 1264 PXOPT_LOOKUP_STR(ver_pslib, config->args, "-ver_pslib", false, false); 1265 PXOPT_LOOKUP_STR(ver_psmodules, config->args, "-ver_psmodules", false, false); 1266 PXOPT_LOOKUP_STR(ver_psphot, config->args, "-ver_psphot", false, false); 1267 PXOPT_LOOKUP_STR(ver_psastro, config->args, "-ver_psastro", false, false); 1268 PXOPT_LOOKUP_STR(ver_ppstats, config->args, "-ver_ppstats", false, false); 1269 1270 psString software_ver = NULL; 1271 if ((ver_pslib)&&(ver_psmodules)) { 1272 software_ver = pxMergeCodeVersions(ver_pslib,ver_psmodules); 1273 } 1274 if (ver_psphot) { 1275 software_ver = pxMergeCodeVersions(software_ver,ver_psphot); 1276 } 1277 if (ver_psastro) { 1278 software_ver = pxMergeCodeVersions(software_ver,ver_psastro); 1279 } 1280 if (ver_ppstats) { 1281 software_ver = pxMergeCodeVersions(software_ver,ver_ppstats); 1282 } 1283 1284 if (!psDBTransaction(config->dbh)) { 1285 psError(PS_ERR_UNKNOWN, false, "database error"); 1286 return false; 1287 } 1288 1289 skycalResultRow *row = skycalResultRowAlloc( 1290 skycal_id, 1291 path_base, 1292 dtime_script, 1293 dtime_astrom, 1294 sigma_ra, 1295 sigma_dec, 1296 n_astrom, 1297 zpt_obs, 1298 zpt_stdev, 1299 quality, 1300 software_ver, 1301 hostname, 1302 fault 1303 ); 1304 1305 if (!skycalResultInsertObject(config->dbh, row)) { 1306 // rollback 1307 if (!psDBRollback(config->dbh)) { 1308 psError(PS_ERR_UNKNOWN, false, "database error"); 1309 } 1310 psError(PS_ERR_UNKNOWN, false, "database error"); 1311 psFree(row); 1312 return false; 1313 } 1314 1315 psFree(row); 1316 1317 if (fault) { 1318 if (!psDBCommit(config->dbh)) { 1319 psError(PS_ERR_UNKNOWN, false, "database error"); 1320 return false; 1321 } 1322 return true; 1323 } 1324 1325 psString query = "UPDATE skycalRun SET state = 'full' WHERE skycal_id = %" PRId64; 1326 if (!p_psDBRunQueryF(config->dbh, query, skycal_id)) { 1327 psError(PS_ERR_UNKNOWN, false, "database error"); 1328 return false; 1329 } 1330 if (!psDBCommit(config->dbh)) { 1331 psError(PS_ERR_UNKNOWN, false, "database error"); 1332 return false; 1333 } 1334 1335 return true; 1336 } 1337 static bool updateskycalresultMode(pxConfig *config) 1338 { 1339 PS_ASSERT_PTR_NON_NULL(config, false); 1340 1341 PXOPT_LOOKUP_S16(fault, config->args, "-set_fault", true, false); 1342 PXOPT_LOOKUP_S16(quality, config->args, "-set_quality", false, false); 1343 1344 psMetadata *where = psMetadataAlloc(); 1345 PXOPT_COPY_S64(config->args, where, "-skycal_id", "skycal_id", "=="); 1346 1347 if (!pxSetFaultCode(config->dbh, "skycalResult", where, fault, quality)) { 1348 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); 1349 psFree (where); 1350 return false; 1351 } 1352 psFree (where); 1353 return true; 1354 } 1355 static bool skycalresultMode(pxConfig *config) 1356 { 1357 PS_ASSERT_PTR_NON_NULL(config, false); 1358 1359 psMetadata *where = psMetadataAlloc(); 1360 PXOPT_COPY_S64(config->args, where, "-skycal_id", "skycalRun.skycal_id", "=="); 1361 PXOPT_COPY_S64(config->args, where, "-sky_id", "skycalRun.sky_id", "=="); 1362 PXOPT_COPY_S64(config->args, where, "-stack_id", "skycalRun.stack_id", "=="); 1363 PXOPT_COPY_STR(config->args, where, "-tess_id", "stackRun.tess_id", "LIKE"); 1364 PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "LIKE"); 1365 PXOPT_COPY_STR(config->args, where, "-filter", "stackRun.filter", "LIKE"); 1366 PXOPT_COPY_STR(config->args, where, "-label", "skycalRun.label", "=="); 1367 PXOPT_COPY_STR(config->args, where, "-data_group", "skycalRun.data_group", "LIKE"); 1368 PXOPT_COPY_S16(config->args, where, "-fault", "skycalResult.fault", "=="); 1369 1370 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1371 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1372 1373 psString query = pxDataGet("staticskytool_skycalresult.sql"); 1374 if (!query) { 1375 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1376 return false; 1377 } 1378 1379 if (!psListLength(where->list)) { 1380 psError(PXTOOLS_ERR_CONFIG, true, "search parameters are required"); 1381 return false; 1382 } 1383 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1384 psStringAppend(&query, " WHERE %s", whereClause); 1385 psFree(whereClause); 1386 psFree(where); 1387 1388 // treat limit == 0 as "no limit" 1389 if (limit) { 1390 psString limitString = psDBGenerateLimitSQL(limit); 1391 psStringAppend(&query, " %s", limitString); 1392 psFree(limitString); 1393 } 1394 1395 if (!p_psDBRunQuery(config->dbh, query)) { 1396 psError(PS_ERR_UNKNOWN, false, "database error"); 1397 psFree(query); 1398 return false; 1399 } 1400 psFree(query); 1401 1402 psArray *output = p_psDBFetchResult(config->dbh); 1403 if (!output) { 1404 psErrorCode err = psErrorCodeLast(); 1405 switch (err) { 1406 case PS_ERR_DB_CLIENT: 1407 psError(PXTOOLS_ERR_SYS, false, "database error"); 1408 case PS_ERR_DB_SERVER: 1409 psError(PXTOOLS_ERR_PROG, false, "database error"); 1410 default: 1411 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1412 } 1413 1414 return false; 1415 } 1416 if (!psArrayLength(output)) { 1417 psTrace("staticskytool", PS_LOG_INFO, "no rows found"); 1418 psFree(output); 1419 return true; 1420 } 1421 1422 if (psArrayLength(output)) { 1423 if (!ippdbPrintMetadatas(stdout, output, "staticskyResult", !simple)) { 1424 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1425 psFree(output); 1426 return false; 1427 } 1428 } 1429 1430 psFree(output); 1431 1432 return true; 1433 } 1434 static bool revertskycalresultMode(pxConfig *config) 1435 { 1436 PS_ASSERT_PTR_NON_NULL(config, false); 1437 1438 psMetadata *where = psMetadataAlloc(); 1439 PXOPT_COPY_S64(config->args, where, "-skycal_id", "staticskyResult.sky_id", "=="); 1440 pxAddLabelSearchArgs(config, where, "-label", "staticskyRun.label", "=="); 1441 pxAddLabelSearchArgs(config, where, "-data_group", "staticskyRun.data_group", "=="); 1442 pxAddLabelSearchArgs(config, where, "-filter", "stackRun.filter", "=="); 1443 PXOPT_COPY_S16(config->args, where, "-fault", "staticskyResult.fault", "=="); 1444 1445 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 1446 psFree(where); 1447 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1448 return false; 1449 } 1450 1451 // Delete product 1452 psString delete = pxDataGet("staticskytool_revertskycal.sql"); 1453 if (!delete) { 1454 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1455 return false; 1456 } 1457 1458 if (psListLength(where->list)) { 1459 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1460 psStringAppend(&delete, " AND %s", whereClause); 1461 psFree(whereClause); 1462 } 1463 1464 if (!p_psDBRunQuery(config->dbh, delete)) { 1465 psError(PS_ERR_UNKNOWN, false, "database error"); 1466 psFree(delete); 1467 psFree(where); 1468 return false; 1469 } 1470 psFree(delete); 1471 1472 int numRows = psDBAffectedRows(config->dbh); // Number of row affected 1473 psLogMsg("staticskytool", PS_LOG_INFO, "Deleted %d rows", numRows); 1474 1475 psFree(where); 1476 return true; 1477 }
Note:
See TracChangeset
for help on using the changeset viewer.
