IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17856


Ignore:
Timestamp:
May 29, 2008, 1:28:41 PM (18 years ago)
Author:
jhoblitt
Message:

add createMode() function and mode table creation into pxadmin_create_tables.sql
remove the use of pxtables.c

Location:
trunk/ippTools
Files:
1 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/Makefile.am

    r16277 r17856  
    6868        pxio.c \
    6969        pxregister.c \
    70         pxtables.c \
    7170        pxtag.c \
    7271        pxtoolsErrorCodes.c \
  • trunk/ippTools/src/pxadmin.c

    r17855 r17856  
    2828#include "pxadmin.h"
    2929
     30bool createMode(pxConfig *config);
    3031bool deleteMode(pxConfig *config);
    3132static bool runMultipleStatments(pxConfig *config, const char *query);
     
    4849            // fall through
    4950        case PXADMIN_MODE_CREATE:
    50             if (!pxCreateTables(config)) {
     51            if (!createMode(config)) {
    5152                goto FAIL;
    5253            }
     
    7980}
    8081
     82
     83bool createMode(pxConfig *config)
     84{
     85    PS_ASSERT_PTR_NON_NULL(config, false);
     86
     87    psString query = pxDataGet("pxadmin_create_tables.sql");
     88    if (!query) {
     89        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     90        return false;
     91    }
     92
     93    // BEGIN
     94    if (!psDBTransaction(config->dbh)) {
     95        psError(PS_ERR_UNKNOWN, false, "database error");
     96        return false;
     97    }
     98
     99    if (!runMultipleStatments(config, query)) {
     100        if (!psDBRollback(config->dbh)) {
     101                psError(PS_ERR_UNKNOWN, false, "database error");
     102        }
     103        psError(PS_ERR_UNKNOWN, false, "database error");
     104        psFree(query);
     105        return false;
     106    }
     107    psFree(query);
     108
     109    // COMMIT
     110    if (!psDBCommit(config->dbh)) {
     111        psError(PS_ERR_UNKNOWN, false, "database error");
     112        return false;
     113    }
     114
     115    return true;
     116}
     117
     118
    81119bool deleteMode(pxConfig *config)
    82120{
    83121    PS_ASSERT_PTR_NON_NULL(config, false);
     122
     123    {
     124        bool status;
     125        char line[128], answer[128];
     126
     127        // XXX use the values defined in config->dbh?
     128        psString dbName = psMetadataLookupStr(&status, config->modules->complete, "DBNAME");
     129
     130        fprintf (stdout, "*** delete the chip tables from database %s? ***\n", dbName);
     131        fprintf (stdout, "*** to delete the tables, answer YES, and give password ***\n");
     132        fprintf (stdout, "*** WARNING: this action is permanent ***\n\n");
     133
     134        fprintf (stdout, "delete the chip tables (YES/[n]): ");
     135        fgets (line, 128, stdin);
     136        sscanf (line, "%s", answer);
     137        if (strcmp (answer, "YES"))  {
     138            psError(PS_ERR_UNKNOWN, true, "tables NOT deleleted");
     139            return false;
     140        }
     141
     142        fprintf (stdout, "enter dbh connection password: ");
     143        fgets (line, 128, stdin);
     144        sscanf (line, "%s", answer);
     145
     146        psString dbPassword = psMetadataLookupStr(&status, config->modules->complete, "DBPASSWORD");
     147        if (strcmp (answer, dbPassword)) {
     148            psError(PS_ERR_UNKNOWN, true, "invalid passwd - tables NOT deleleted");
     149            return false;
     150        }
     151    }
    84152
    85153    psString query = pxDataGet("pxadmin_drop_tables.sql");
     
    113181    return true;
    114182}
     183
    115184
    116185static bool runMultipleStatments(pxConfig *config, const char *query)
Note: See TracChangeset for help on using the changeset viewer.