Changeset 17856 for trunk/ippTools/src/pxadmin.c
- Timestamp:
- May 29, 2008, 1:28:41 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pxadmin.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pxadmin.c
r17855 r17856 28 28 #include "pxadmin.h" 29 29 30 bool createMode(pxConfig *config); 30 31 bool deleteMode(pxConfig *config); 31 32 static bool runMultipleStatments(pxConfig *config, const char *query); … … 48 49 // fall through 49 50 case PXADMIN_MODE_CREATE: 50 if (! pxCreateTables(config)) {51 if (!createMode(config)) { 51 52 goto FAIL; 52 53 } … … 79 80 } 80 81 82 83 bool 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 81 119 bool deleteMode(pxConfig *config) 82 120 { 83 121 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 } 84 152 85 153 psString query = pxDataGet("pxadmin_drop_tables.sql"); … … 113 181 return true; 114 182 } 183 115 184 116 185 static bool runMultipleStatments(pxConfig *config, const char *query)
Note:
See TracChangeset
for help on using the changeset viewer.
