Changeset 25822 for trunk/ippTools/src/magicdstool.c
- Timestamp:
- Oct 9, 2009, 2:02:24 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/magicdstool.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/magicdstool.c
r25792 r25822 43 43 static bool torevertMode(pxConfig *config); 44 44 static bool completedrevertMode(pxConfig *config); 45 static bool tocleanupMode(pxConfig *config); 45 46 46 47 static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, psMetadata *where, const char *state); … … 76 77 MODECASE(MAGICDSTOOL_MODE_TOREVERT, torevertMode); 77 78 MODECASE(MAGICDSTOOL_MODE_COMPLETEDREVERT, completedrevertMode); 79 MODECASE(MAGICDSTOOL_MODE_TOCLEANUP, tocleanupMode); 78 80 default: 79 81 psAbort("invalid option (this should not happen)"); … … 1221 1223 1222 1224 1225 static bool tocleanupMode(pxConfig *config) 1226 { 1227 PS_ASSERT_PTR_NON_NULL(config, false); 1228 1229 psMetadata *where = psMetadataAlloc(); 1230 1231 PXOPT_COPY_S64(config->args, where, "-stage", "stage", "=="); 1232 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "=="); 1233 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 1234 pxAddLabelSearchArgs (config, where, "-label", "magicDSRun.label", "=="); 1235 1236 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1237 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1238 1239 psString query = pxDataGet("magicdstool_tocleanup.sql"); 1240 if (!query) { 1241 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1242 return false; 1243 } 1244 1245 if (psListLength(where->list)) { 1246 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1247 psStringAppend(&query, " AND %s", whereClause); 1248 psFree(whereClause); 1249 } 1250 psFree(where); 1251 1252 // treat limit == 0 as "no limit" 1253 if (limit) { 1254 psString limitString = psDBGenerateLimitSQL(limit); 1255 psStringAppend(&query, " %s", limitString); 1256 psFree(limitString); 1257 } 1258 1259 if (!p_psDBRunQuery(config->dbh, query)) { 1260 psError(PS_ERR_UNKNOWN, false, "database error"); 1261 psFree(query); 1262 return false; 1263 } 1264 psFree(query); 1265 1266 psArray *output = p_psDBFetchResult(config->dbh); 1267 if (!output) { 1268 psErrorCode err = psErrorCodeLast(); 1269 switch (err) { 1270 case PS_ERR_DB_CLIENT: 1271 psError(PXTOOLS_ERR_SYS, false, "database error"); 1272 case PS_ERR_DB_SERVER: 1273 psError(PXTOOLS_ERR_PROG, false, "database error"); 1274 default: 1275 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1276 } 1277 1278 return false; 1279 } 1280 if (!psArrayLength(output)) { 1281 psTrace("magicdstool", PS_LOG_INFO, "no rows found"); 1282 psFree(output); 1283 return true; 1284 } 1285 1286 if (psArrayLength(output)) { 1287 // negative simple so the default is true 1288 if (!ippdbPrintMetadatas(stdout, output, "tocleanup", !simple)) { 1289 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1290 psFree(output); 1291 return false; 1292 } 1293 } 1294 1295 psFree(output); 1296 1297 return true; 1298 }
Note:
See TracChangeset
for help on using the changeset viewer.
