IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 11, 2012, 11:19:21 PM (15 years ago)
Author:
mhuber
Message:

merged latest r33093 trunk changes to meh_branches/ppsub_test

Location:
branches/meh_branches/ppsub_test
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/meh_branches/ppsub_test

  • branches/meh_branches/ppsub_test/ippTools/src

  • branches/meh_branches/ppsub_test/ippTools/src/staticskytool.c

    r31690 r33098  
    3838static bool resultMode(pxConfig *config);
    3939static bool revertMode(pxConfig *config);
    40 static bool updateresult(pxConfig *config);
     40static bool updateresultMode(pxConfig *config);
    4141static bool exportrunMode(pxConfig *config);
    4242static bool importrunMode(pxConfig *config);
     43
     44static bool defineskycalrunMode(pxConfig *config);
     45static bool updateskycalrunMode(pxConfig *config);
     46static bool pendingskycalrunMode(pxConfig *config);
     47static bool addskycalresultMode(pxConfig *config);
     48static bool skycalresultMode(pxConfig *config);
     49static bool revertskycalresultMode(pxConfig *config);
     50static bool updateskycalresultMode(pxConfig *config);
    4351
    4452static bool setstaticskyRunState(pxConfig *config, psS64 sky_id, const char *state);
     
    6977        MODECASE(STATICSKYTOOL_MODE_RESULT,            resultMode);
    7078        MODECASE(STATICSKYTOOL_MODE_REVERT,            revertMode);
    71         MODECASE(STATICSKYTOOL_MODE_UPDATERESULT,      updateresult);
     79        MODECASE(STATICSKYTOOL_MODE_UPDATERESULT,      updateresultMode);
    7280        MODECASE(STATICSKYTOOL_MODE_EXPORTRUN,         exportrunMode);
    7381        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);
    7489        default:
    7590            psAbort("invalid option (this should not happen)");
     
    97112{
    98113    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);
    102116
    103117    // optional
    104     PXOPT_LOOKUP_STR(label,       config->args, "-set_label", true, false);
    105118    PXOPT_LOOKUP_STR(data_group,  config->args, "-set_data_group", false, false);
    106119    PXOPT_LOOKUP_STR(dist_group,  config->args, "-set_dist_group", false, false);
     
    111124    psMetadata *whereMD = psMetadataAlloc();
    112125
    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");
    114128    PXOPT_COPY_STR(config->args, whereMD, "-select_tess_id",       "stackRun.tess_id",          "==");
    115129    PXOPT_COPY_F32(config->args, whereMD, "-select_good_frac_min", "stackSumSkyfile.good_frac", ">=");
     
    735749}
    736750
    737 static bool updateresult(pxConfig *config)
     751static bool updateresultMode(pxConfig *config)
    738752{
    739753    PS_ASSERT_PTR_NON_NULL(config, false);
     
    978992# endif
    979993
     994static bool defineskycalrunMode(pxConfig *config)
     995{
     996    PS_ASSERT_PTR_NON_NULL(config, false);
     997
     998    // required options
     999    // none required. We get workdir, etc from staticskyRun if not provided
     1000
     1001    // optional
     1002    PXOPT_LOOKUP_STR(label,       config->args, "-set_label", false, false);
     1003    PXOPT_LOOKUP_STR(workdir,     config->args, "-set_workdir", false, false);
     1004    PXOPT_LOOKUP_STR(data_group,  config->args, "-set_data_group", false, false);
     1005    PXOPT_LOOKUP_STR(dist_group,  config->args, "-set_dist_group", false, false);
     1006    PXOPT_LOOKUP_STR(reduction,   config->args, "-set_reduction", false, false);
     1007    PXOPT_LOOKUP_STR(note,        config->args, "-set_note", false, false);
     1008    PXOPT_LOOKUP_TIME(registered, config->args, "-set_registered", false, false);
     1009
     1010    psMetadata *whereMD = psMetadataAlloc();
     1011
     1012    PXOPT_COPY_S64(config->args, whereMD, "-select_sky_id",        "staticskyRun.sky_id",       "==");
     1013    PXOPT_COPY_S64(config->args, whereMD, "-select_stack_id",      "stackRun.stack_id",         "==");
     1014    PXOPT_COPY_STR(config->args, whereMD, "-select_skycell_id",    "stackRun.skycell_id",       "==");
     1015    PXOPT_COPY_STR(config->args, whereMD, "-select_tess_id",       "stackRun.tess_id",          "==");
     1016    PXOPT_COPY_F32(config->args, whereMD, "-select_good_frac_min", "stackSumSkyfile.good_frac", ">=");
     1017    pxAddLabelSearchArgs(config, whereMD, "-select_label",         "stackRun.label",            "LIKE");
     1018    pxAddLabelSearchArgs(config, whereMD, "-select_data_group",    "stackRun.data_group",       "LIKE");
     1019    pxAddLabelSearchArgs(config, whereMD, "-select_filter",        "stackRun.filter",           "LIKE");
     1020
     1021    PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false);
     1022    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1023    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
     1024
     1025    psString query = pxDataGet("staticskytool_defineskycalrun.sql");
     1026    if (!query) {
     1027        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1028        psFree(whereMD);
     1029        return false;
     1030    }
     1031
     1032    if (!psListLength(whereMD->list)) {
     1033        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     1034        psFree(whereMD);
     1035        return false;
     1036    }
     1037
     1038    psString whereClause = psDBGenerateWhereConditionSQL(whereMD, NULL);
     1039    psStringAppend(&query, "\nAND %s", whereClause);
     1040    psFree(whereClause);
     1041    psFree(whereMD);
     1042
     1043    if (!rerun) {
     1044        if (label)  {
     1045            psStringAppend(&query, "\nAND (skycalRun.label IS NULL OR skycalRun.label = '%s')", label);
     1046        }
     1047        psStringAppend(&query, "\nAND skycal_id IS NULL");
     1048    }
     1049
     1050    if (!p_psDBRunQuery(config->dbh, query)) {
     1051        psError(PS_ERR_UNKNOWN, false, "database error");
     1052        psFree(query);
     1053        return false;
     1054    }
     1055    psFree(query);
     1056
     1057    // we now have a list of (tess_id, skycell_id) that (potentially) meet out needs
     1058    // we now need to loop over all of these and for each pair, select the best set of
     1059    // inputs
     1060
     1061    psArray *output = p_psDBFetchResult(config->dbh);
     1062    if (!output) {
     1063        psErrorCode err = psErrorCodeLast();
     1064        switch (err) {
     1065            case PS_ERR_DB_CLIENT:
     1066                psError(PXTOOLS_ERR_SYS, false, "database error");
     1067            case PS_ERR_DB_SERVER:
     1068                psError(PXTOOLS_ERR_PROG, false, "database error");
     1069            default:
     1070                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1071        }
     1072        return false;
     1073    }
     1074    if (!psArrayLength(output)) {
     1075        psWarning("staticskytool: no rows found");
     1076        psFree(output);
     1077        return true;
     1078    }
     1079    if (pretend) {
     1080        // negative simple so the default is true
     1081        if (!ippdbPrintMetadatas(stdout, output, "skycalRun", !simple)) {
     1082            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1083            psFree(output);
     1084            return false;
     1085        }
     1086        psFree(output);
     1087        return true;
     1088    }
     1089
     1090    for (long i = 0; i < output->n; i++) {
     1091        psMetadata *row = output->data[i]; // Row from select
     1092        bool status;
     1093
     1094        psS64 sky_id = psMetadataLookupS64(&status, row, "sky_id");
     1095        psS64 stack_id = psMetadataLookupS64(&status, row, "stack_id");
     1096        psString sky_workdir = psMetadataLookupStr(&status, row, "workdir");
     1097        psString sky_label =  psMetadataLookupStr(&status, row, "label");
     1098        psString sky_data_group =  psMetadataLookupStr(&status, row, "data_group");
     1099
     1100        // create a staticskyRun
     1101        if (!skycalRunInsert(config->dbh,
     1102                                0x0,         // skycal_id
     1103                                sky_id,
     1104                                stack_id,
     1105                                "new",       // state
     1106                                workdir ? workdir : sky_workdir,
     1107                                label ? label : sky_label,
     1108                                data_group ? data_group : sky_data_group,
     1109                                dist_group,
     1110                                reduction,
     1111                                registered,
     1112                                note
     1113                )
     1114            ) {
     1115            psError(PS_ERR_UNKNOWN, false, "database error");
     1116            psFree(output);
     1117            return false;
     1118        }
     1119
     1120    }
     1121    psFree(output);
     1122    return true;
     1123}
     1124
     1125static bool updateskycalrunMode(pxConfig *config)
     1126{
     1127#ifdef notyet
     1128    PS_ASSERT_PTR_NON_NULL(config, false);
     1129
     1130    psMetadata *where = psMetadataAlloc();
     1131    PXOPT_COPY_S64(config->args, where, "-sky_id",  "sky_id",   "==");
     1132    PXOPT_COPY_STR(config->args, where, "-label",   "label",    "==");
     1133    PXOPT_COPY_STR(config->args, where, "-state",   "state",    "==");
     1134    if (!psListLength(where->list)) {
     1135        psFree(where);
     1136        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     1137        return false;
     1138    }
     1139
     1140    psString query = psStringCopy("UPDATE staticskyRun");
     1141
     1142    // pxUpdateRun gets parameters from config->args and updates
     1143    bool result = pxUpdateRun(config, where, &query, "staticskyRun", "sky_id", "staticskyResult", true, false);
     1144    psFree(query);
     1145    psFree(where);
     1146
     1147    return result;
     1148#endif
     1149    return false;
     1150}
     1151static bool pendingskycalrunMode(pxConfig *config)
     1152{
     1153    PS_ASSERT_PTR_NON_NULL(config, false);
     1154
     1155    psMetadata *whereMD = psMetadataAlloc();
     1156    PXOPT_COPY_S64(config->args, whereMD, "-skycal_id", "skycal_id", "==");
     1157    PXOPT_COPY_S64(config->args, whereMD, "-sky_id", "sky_id", "==");
     1158    pxAddLabelSearchArgs (config, whereMD, "-label", "skycalRun.label", "==");
     1159    PXOPT_COPY_STR(config->args, whereMD, "-filter", "stackRun.filter", "LIKE");
     1160
     1161    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1162    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1163
     1164    psString query = pxDataGet("staticskytool_pendingskycalrun.sql");
     1165    if (!query) {
     1166        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1167        return false;
     1168    }
     1169
     1170    if (!psListLength(whereMD->list)) {
     1171        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     1172        psFree(whereMD);
     1173        return false;
     1174    }
     1175
     1176    psString whereClause = psDBGenerateWhereConditionSQL(whereMD, NULL);
     1177    psStringAppend(&query, "\n AND %s", whereClause);
     1178    psFree(whereClause);
     1179    psFree(whereMD);
     1180
     1181    // treat limit == 0 as "no limit"
     1182    if (limit) {
     1183        psString limitString = psDBGenerateLimitSQL(limit);
     1184        psStringAppend(&query, "\n%s", limitString);
     1185        psFree(limitString);
     1186    }
     1187
     1188    // the where clause is required and matches the WHERE hook format string
     1189    if (!p_psDBRunQuery(config->dbh, query)) {
     1190        psError(PS_ERR_UNKNOWN, false, "database error");
     1191        psFree(query);
     1192        return false;
     1193    }
     1194    psFree(query);
     1195
     1196    psArray *output = p_psDBFetchResult(config->dbh);
     1197    if (!output) {
     1198        psErrorCode err = psErrorCodeLast();
     1199        switch (err) {
     1200            case PS_ERR_DB_CLIENT:
     1201                psError(PXTOOLS_ERR_SYS, false, "database error");
     1202            case PS_ERR_DB_SERVER:
     1203                psError(PXTOOLS_ERR_PROG, false, "database error");
     1204            default:
     1205                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1206        }
     1207
     1208        return false;
     1209    }
     1210    if (!psArrayLength(output)) {
     1211        psTrace("staticskytool", PS_LOG_INFO, "no rows found");
     1212        psFree(output);
     1213        return true;
     1214    }
     1215
     1216    if (psArrayLength(output)) {
     1217        // negative simple so the default is true
     1218        if (!ippdbPrintMetadatas(stdout, output, "pendingskycalRun", !simple)) {
     1219            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1220            psFree(output);
     1221            return false;
     1222        }
     1223    }
     1224
     1225    psFree(output);
     1226    return true;
     1227}
     1228
     1229static bool addskycalresultMode(pxConfig *config)
     1230{
     1231    PS_ASSERT_PTR_NON_NULL(config, false);
     1232
     1233    // required
     1234    PXOPT_LOOKUP_S64(skycal_id, config->args, "-skycal_id", true, false);
     1235
     1236    // optional
     1237    PXOPT_LOOKUP_F32(sigma_ra, config->args,  "-sigma_ra", false, false);
     1238    PXOPT_LOOKUP_F32(sigma_dec, config->args, "-sigma_dec", false, false);
     1239
     1240    PXOPT_LOOKUP_F32(zpt_obs, config->args,   "-zpt_obs", false, false);
     1241    PXOPT_LOOKUP_F32(zpt_stdev, config->args, "-zpt_stdev", false, false);
     1242
     1243
     1244    PXOPT_LOOKUP_F32(dtime_script, config->args,   "-dtime_script", false, false);
     1245    PXOPT_LOOKUP_F32(dtime_astrom, config->args,   "-dtime_astrom", false, false);
     1246
     1247    PXOPT_LOOKUP_STR(hostname, config->args,    "-hostname", false, false);
     1248//    PXOPT_LOOKUP_S32(n_stars, config->args,     "-n_stars", false, false);
     1249    PXOPT_LOOKUP_S32(n_astrom, config->args,    "-n_astrom", false, false);
     1250
     1251    PXOPT_LOOKUP_STR(path_base, config->args,   "-path_base", false, false);
     1252    PXOPT_LOOKUP_S16(fault, config->args,       "-fault", false, false);
     1253    PXOPT_LOOKUP_S16(quality, config->args,     "-quality", false, false);
     1254
     1255    PXOPT_LOOKUP_STR(ver_pslib, config->args,   "-ver_pslib", false, false);
     1256    PXOPT_LOOKUP_STR(ver_psmodules, config->args, "-ver_psmodules", false, false);
     1257    PXOPT_LOOKUP_STR(ver_psphot, config->args,  "-ver_psphot", false, false);
     1258    PXOPT_LOOKUP_STR(ver_psastro, config->args, "-ver_psastro", false, false);
     1259    PXOPT_LOOKUP_STR(ver_ppstats, config->args, "-ver_ppstats", false, false);
     1260
     1261    psString software_ver = NULL;
     1262    if ((ver_pslib)&&(ver_psmodules)) {
     1263      software_ver = pxMergeCodeVersions(ver_pslib,ver_psmodules);
     1264    }
     1265    if (ver_psphot) {
     1266      software_ver = pxMergeCodeVersions(software_ver,ver_psphot);
     1267    }
     1268    if (ver_psastro) {
     1269      software_ver = pxMergeCodeVersions(software_ver,ver_psastro);
     1270    }
     1271    if (ver_ppstats) {
     1272      software_ver = pxMergeCodeVersions(software_ver,ver_ppstats);
     1273    }
     1274
     1275    if (!psDBTransaction(config->dbh)) {
     1276        psError(PS_ERR_UNKNOWN, false, "database error");
     1277        return false;
     1278    }
     1279
     1280    skycalResultRow *row = skycalResultRowAlloc(
     1281        skycal_id,
     1282        path_base,
     1283        dtime_script,
     1284        dtime_astrom,
     1285        sigma_ra,
     1286        sigma_dec,
     1287        n_astrom,
     1288        zpt_obs,
     1289        zpt_stdev,
     1290        quality,
     1291        software_ver,
     1292        hostname,
     1293        fault
     1294        );
     1295
     1296    if (!skycalResultInsertObject(config->dbh, row)) {
     1297        // rollback
     1298        if (!psDBRollback(config->dbh)) {
     1299            psError(PS_ERR_UNKNOWN, false, "database error");
     1300        }
     1301        psError(PS_ERR_UNKNOWN, false, "database error");
     1302        psFree(row);
     1303        return false;
     1304    }
     1305
     1306    psFree(row);
     1307
     1308    if (fault) {
     1309        if (!psDBCommit(config->dbh)) {
     1310            psError(PS_ERR_UNKNOWN, false, "database error");
     1311            return false;
     1312        }
     1313        return true;
     1314    }
     1315
     1316    psString query = "UPDATE skycalRun SET state = 'full' WHERE skycal_id = %" PRId64;
     1317    if (!p_psDBRunQueryF(config->dbh, query, skycal_id)) {
     1318        psError(PS_ERR_UNKNOWN, false, "database error");
     1319        return false;
     1320    }
     1321    if (!psDBCommit(config->dbh)) {
     1322        psError(PS_ERR_UNKNOWN, false, "database error");
     1323        return false;
     1324    }
     1325
     1326    return true;
     1327}
     1328static bool updateskycalresultMode(pxConfig *config)
     1329{
     1330    PS_ASSERT_PTR_NON_NULL(config, false);
     1331
     1332    PXOPT_LOOKUP_S16(fault, config->args, "-set_fault", true, false);
     1333    PXOPT_LOOKUP_S16(quality, config->args, "-set_quality", false, false);
     1334
     1335    psMetadata *where = psMetadataAlloc();
     1336    PXOPT_COPY_S64(config->args, where, "-skycal_id",   "skycal_id",   "==");
     1337
     1338    if (!pxSetFaultCode(config->dbh, "skycalResult", where, fault, quality)) {
     1339        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
     1340        psFree (where);
     1341        return false;
     1342    }
     1343    psFree (where);
     1344    return true;
     1345}
     1346static bool skycalresultMode(pxConfig *config)
     1347{
     1348    PS_ASSERT_PTR_NON_NULL(config, false);
     1349
     1350    psMetadata *where = psMetadataAlloc();
     1351    PXOPT_COPY_S64(config->args, where, "-skycal_id",  "skycalRun.skycal_id", "==");
     1352    PXOPT_COPY_S64(config->args, where, "-sky_id",     "skycalRun.sky_id", "==");
     1353    PXOPT_COPY_S64(config->args, where, "-stack_id",   "skycalRun.stack_id", "==");
     1354    PXOPT_COPY_STR(config->args, where, "-tess_id",    "stackRun.tess_id", "LIKE");
     1355    PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "LIKE");
     1356    PXOPT_COPY_STR(config->args, where, "-filter",     "stackRun.filter", "LIKE");
     1357    PXOPT_COPY_STR(config->args, where, "-label",      "skycalRun.label", "==");
     1358    PXOPT_COPY_STR(config->args, where, "-data_group", "skycalRun.data_group", "LIKE");
     1359    PXOPT_COPY_S16(config->args, where, "-fault",      "skycalResult.fault", "==");
     1360
     1361    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1362    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1363
     1364    psString query = pxDataGet("staticskytool_skycalresult.sql");
     1365    if (!query) {
     1366        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1367        return false;
     1368    }
     1369
     1370    if (!psListLength(where->list)) {
     1371        psError(PXTOOLS_ERR_CONFIG, true, "search parameters are required");
     1372        return false;
     1373    }
     1374    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1375    psStringAppend(&query, " WHERE %s", whereClause);
     1376    psFree(whereClause);
     1377    psFree(where);
     1378
     1379    // treat limit == 0 as "no limit"
     1380    if (limit) {
     1381        psString limitString = psDBGenerateLimitSQL(limit);
     1382        psStringAppend(&query, " %s", limitString);
     1383        psFree(limitString);
     1384    }
     1385
     1386    if (!p_psDBRunQuery(config->dbh, query)) {
     1387        psError(PS_ERR_UNKNOWN, false, "database error");
     1388        psFree(query);
     1389        return false;
     1390    }
     1391    psFree(query);
     1392
     1393    psArray *output = p_psDBFetchResult(config->dbh);
     1394    if (!output) {
     1395        psErrorCode err = psErrorCodeLast();
     1396        switch (err) {
     1397            case PS_ERR_DB_CLIENT:
     1398                psError(PXTOOLS_ERR_SYS, false, "database error");
     1399            case PS_ERR_DB_SERVER:
     1400                psError(PXTOOLS_ERR_PROG, false, "database error");
     1401            default:
     1402                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1403        }
     1404
     1405        return false;
     1406    }
     1407    if (!psArrayLength(output)) {
     1408        psTrace("staticskytool", PS_LOG_INFO, "no rows found");
     1409        psFree(output);
     1410        return true;
     1411    }
     1412
     1413    if (psArrayLength(output)) {
     1414        if (!ippdbPrintMetadatas(stdout, output, "staticskyResult", !simple)) {
     1415            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1416            psFree(output);
     1417            return false;
     1418        }
     1419    }
     1420
     1421    psFree(output);
     1422
     1423    return true;
     1424}
     1425static bool revertskycalresultMode(pxConfig *config)
     1426{
     1427    PS_ASSERT_PTR_NON_NULL(config, false);
     1428
     1429    psMetadata *where = psMetadataAlloc();
     1430    PXOPT_COPY_S64(config->args, where, "-skycal_id", "staticskyResult.sky_id", "==");
     1431    pxAddLabelSearchArgs(config, where, "-label", "staticskyRun.label", "==");
     1432    pxAddLabelSearchArgs(config, where, "-data_group", "staticskyRun.data_group", "==");
     1433    pxAddLabelSearchArgs(config, where, "-filter", "stackRun.filter", "==");
     1434    PXOPT_COPY_S16(config->args, where, "-fault", "staticskyResult.fault", "==");
     1435
     1436    if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
     1437        psFree(where);
     1438        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     1439        return false;
     1440    }
     1441
     1442    // Delete product
     1443    psString delete = pxDataGet("staticskytool_revertskycal.sql");
     1444    if (!delete) {
     1445        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1446        return false;
     1447    }
     1448
     1449    if (psListLength(where->list)) {
     1450        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1451        psStringAppend(&delete, " AND %s", whereClause);
     1452        psFree(whereClause);
     1453    }
     1454
     1455    if (!p_psDBRunQuery(config->dbh, delete)) {
     1456        psError(PS_ERR_UNKNOWN, false, "database error");
     1457        psFree(delete);
     1458        psFree(where);
     1459        return false;
     1460    }
     1461    psFree(delete);
     1462
     1463    int numRows = psDBAffectedRows(config->dbh); // Number of row affected
     1464    psLogMsg("staticskytool", PS_LOG_INFO, "Deleted %d rows", numRows);
     1465
     1466    psFree(where);
     1467    return true;
     1468}
Note: See TracChangeset for help on using the changeset viewer.