IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 13, 2008, 11:22:47 AM (17 years ago)
Author:
Paul Price
Message:

Making warptool -revertwarped also set the state so that it runs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/warptool.c

    r20440 r20722  
    12131213    }
    12141214
    1215     psString query = pxDataGet("warptool_revertwarped.sql");
    1216     if (!query) {
    1217         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1215    if (!psDBTransaction(config->dbh)) {
     1216        psError(PS_ERR_UNKNOWN, false, "database error");
    12181217        psFree(where);
    12191218        return false;
    12201219    }
    12211220
    1222     if (where && psListLength(where->list)) {
    1223         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    1224         psStringAppend(&query, " AND %s", whereClause);
    1225         psFree(whereClause);
     1221    int num;                            // Number affected
     1222
     1223    // Update state to 'new'
     1224    {
     1225        psString query = pxDataGet("warptool_revertwarped_update.sql");
     1226        if (!query) {
     1227            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1228            if (!psDBRollback(config->dbh)) {
     1229                psError(PS_ERR_UNKNOWN, false, "database error");
     1230            }
     1231            return false;
     1232        }
     1233
     1234        if (psListLength(where->list)) {
     1235            psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1236            psStringAppend(&query, " AND %s", whereClause);
     1237            psFree(whereClause);
     1238        }
     1239
     1240        if (!p_psDBRunQuery(config->dbh, query)) {
     1241            psError(PS_ERR_UNKNOWN, false, "database error");
     1242            psFree(query);
     1243            if (!psDBRollback(config->dbh)) {
     1244                psError(PS_ERR_UNKNOWN, false, "database error");
     1245            }
     1246            return false;
     1247        }
     1248        psFree(query);
     1249
     1250        num = psDBAffectedRows(config->dbh);
     1251
     1252        if (num < 1) {
     1253            psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row");
     1254            if (!psDBRollback(config->dbh)) {
     1255                psError(PS_ERR_UNKNOWN, false, "database error");
     1256            }
     1257            return false;
     1258        }
     1259    }
     1260
     1261    // Delete product
     1262    {
     1263        psString query = pxDataGet("warptool_revertwarped_delete.sql");
     1264        if (!query) {
     1265            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1266            if (!psDBRollback(config->dbh)) {
     1267                psError(PS_ERR_UNKNOWN, false, "database error");
     1268            }
     1269            return false;
     1270        }
     1271
     1272        if (psListLength(where->list)) {
     1273            psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1274            psStringAppend(&query, " AND %s", whereClause);
     1275            psFree(whereClause);
     1276        }
     1277
     1278        if (!p_psDBRunQuery(config->dbh, query)) {
     1279            psError(PS_ERR_UNKNOWN, false, "database error");
     1280            psFree(query);
     1281            if (!psDBRollback(config->dbh)) {
     1282                psError(PS_ERR_UNKNOWN, false, "database error");
     1283            }
     1284            return false;
     1285        }
     1286        psFree(query);
     1287
     1288        if (psDBAffectedRows(config->dbh) != num) {
     1289            psError(PS_ERR_UNKNOWN, false, "Updated and deleted different number of entries!");
     1290            if (!psDBRollback(config->dbh)) {
     1291                psError(PS_ERR_UNKNOWN, false, "database error");
     1292            }
     1293            return false;
     1294        }
    12261295    }
    12271296
    12281297    psFree(where);
    12291298
    1230     if (!p_psDBRunQuery(config->dbh, query)) {
    1231         psError(PS_ERR_UNKNOWN, false, "database error");
    1232         psFree(query);
    1233         return false;
    1234     }
    1235     psFree(query);
     1299    if (!psDBCommit(config->dbh)) {
     1300        psError(PS_ERR_UNKNOWN, false, "database error");
     1301        return false;
     1302    }
    12361303
    12371304    return true;
Note: See TracChangeset for help on using the changeset viewer.