IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 12, 2008, 10:26:04 AM (18 years ago)
Author:
Paul Price
Message:

Make 'stacktool -revertsumskyfile' to update the run state as well as delete the offending product.

File:
1 edited

Legend:

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

    r18976 r19029  
    767767    PXOPT_COPY_S16(config->args, where, "-code", "fault", "==");
    768768
    769     psString query = pxDataGet("stacktool_revertsumskyfile.sql");
    770     if (!query) {
    771         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    772         return false;
    773     }
    774 
    775     if (psListLength(where->list)) {
    776         psString whereClause = psDBGenerateWhereConditionSQL(where, "stackSumSkyfile");
    777         psStringAppend(&query, " AND %s", whereClause);
    778         psFree(whereClause);
    779     }
     769    if (!psDBTransaction(config->dbh)) {
     770        psError(PS_ERR_UNKNOWN, false, "database error");
     771        psFree(where);
     772        return false;
     773    }
     774
     775    int numStacks;                      // Number of stacks affected
     776
     777    // Update state to 'run'
     778    {
     779        psString update = pxDataGet("stacktool_revertsumskyfile_update.sql");
     780        if (!update) {
     781            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     782            if (!psDBRollback(config->dbh)) {
     783                psError(PS_ERR_UNKNOWN, false, "database error");
     784            }
     785            return false;
     786        }
     787
     788        if (psListLength(where->list)) {
     789            psString whereClause = psDBGenerateWhereConditionSQL(where, "stackSumSkyfile");
     790            psStringAppend(&update, " AND %s", whereClause);
     791            psFree(whereClause);
     792        }
     793
     794        if (!p_psDBRunQuery(config->dbh, update)) {
     795            psError(PS_ERR_UNKNOWN, false, "database error");
     796            psFree(update);
     797            psFree(where);
     798            if (!psDBRollback(config->dbh)) {
     799                psError(PS_ERR_UNKNOWN, false, "database error");
     800            }
     801            return false;
     802        }
     803        psFree(update);
     804
     805        numStacks = psDBAffectedRows(config->dbh);
     806
     807        if (numStacks < 1) {
     808            psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row");
     809            if (!psDBRollback(config->dbh)) {
     810                psError(PS_ERR_UNKNOWN, false, "database error");
     811            }
     812            return false;
     813        }
     814    }
     815
     816    // Delete product
     817    {
     818        psString delete = pxDataGet("stacktool_revertsumskyfile_delete.sql");
     819        if (!delete) {
     820            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     821            if (!psDBRollback(config->dbh)) {
     822                psError(PS_ERR_UNKNOWN, false, "database error");
     823            }
     824            return false;
     825        }
     826
     827        if (psListLength(where->list)) {
     828            psString whereClause = psDBGenerateWhereConditionSQL(where, "stackSumSkyfile");
     829            psStringAppend(&delete, " AND %s", whereClause);
     830            psFree(whereClause);
     831        }
     832
     833        if (!p_psDBRunQuery(config->dbh, delete)) {
     834            psError(PS_ERR_UNKNOWN, false, "database error");
     835            psFree(delete);
     836            psFree(where);
     837            if (!psDBRollback(config->dbh)) {
     838                psError(PS_ERR_UNKNOWN, false, "database error");
     839            }
     840            return false;
     841        }
     842        psFree(delete);
     843
     844        if (psDBAffectedRows(config->dbh) != numStacks) {
     845            psError(PS_ERR_UNKNOWN, true, "Updated and deleted different number of entries!");
     846            psFree(where);
     847            if (!psDBRollback(config->dbh)) {
     848                psError(PS_ERR_UNKNOWN, false, "database error");
     849            }
     850            return false;
     851        }
     852
     853    }
     854
     855    if (!psDBCommit(config->dbh)) {
     856        psError(PS_ERR_UNKNOWN, false, "database error");
     857        return false;
     858    }
     859
    780860    psFree(where);
    781 
    782     if (!p_psDBRunQuery(config->dbh, query)) {
    783         psError(PS_ERR_UNKNOWN, false, "database error");
    784         psFree(query);
    785         return false;
    786     }
    787     psFree(query);
    788 
    789     if (psDBAffectedRows(config->dbh) < 1) {
    790         psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row");
    791         return false;
    792     }
    793861
    794862    return true;
Note: See TracChangeset for help on using the changeset viewer.