IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 29, 2008, 11:59:21 AM (18 years ago)
Author:
jhoblitt
Message:

use share/pxadmin_drop_tables.sql to drop tables instead of the ippdb functions

File:
1 edited

Legend:

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

    r11840 r17854  
    2323
    2424#include <stdlib.h>
     25#include <string.h>
    2526
    2627#include "pxtools.h"
    2728#include "pxadmin.h"
     29
     30bool deleteMode(pxConfig *config);
    2831
    2932int main(int argc, char **argv)
     
    3942    switch (config->mode) {
    4043        case PXADMIN_MODE_RECREATE:
    41             if (!pxDeleteTables(config)) {
     44            if (!deleteMode(config)) {
    4245                goto FAIL;
    4346            }
     
    4952            break;
    5053        case PXADMIN_MODE_DELETE:
    51             if (!pxDeleteTables(config)) {
     54            if (!deleteMode(config)) {
    5255                goto FAIL;
    5356            }
     
    7477    exit(exit_status);
    7578}
     79
     80bool deleteMode(pxConfig *config)
     81{
     82    PS_ASSERT_PTR_NON_NULL(config, false);
     83
     84    psString query = pxDataGet("pxadmin_drop_tables.sql");
     85    if (!query) {
     86        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     87        return false;
     88    }
     89
     90    // BEGIN
     91    if (!psDBTransaction(config->dbh)) {
     92        psError(PS_ERR_UNKNOWN, false, "database error");
     93        return false;
     94    }
     95
     96    // loop over all statements in string
     97    psList *statements = psStringSplit(query, ";", false);
     98    psFree(query);
     99
     100    psString q = NULL;
     101    psListIterator *iter = psListIteratorAlloc(statements, PS_LIST_HEAD, false);
     102    while ((q = psListGetAndIncrement(iter))) {
     103        if (!p_psDBRunQuery(config->dbh, q)) {
     104            if (!psDBRollback(config->dbh)) {
     105                psError(PS_ERR_UNKNOWN, false, "database error");
     106            }
     107            psError(PS_ERR_UNKNOWN, false, "database error");
     108            psFree(iter);
     109            psFree(statements);
     110            return false;
     111        }
     112    }
     113    psFree(iter);
     114    psFree(statements);
     115
     116    // COMMIT
     117    if (!psDBCommit(config->dbh)) {
     118        psError(PS_ERR_UNKNOWN, false, "database error");
     119        return false;
     120    }
     121
     122    return true;
     123}
Note: See TracChangeset for help on using the changeset viewer.