Changeset 16957
- Timestamp:
- Mar 12, 2008, 11:20:53 AM (18 years ago)
- Location:
- trunk/ippTools/src
- Files:
-
- 3 edited
-
pstamptool.c (modified) (5 diffs)
-
pstamptool.h (modified) (1 diff)
-
pstamptoolConfig.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pstamptool.c
r16931 r16957 35 35 static bool moddatastoreMode(pxConfig *config); 36 36 static bool addReqMode(pxConfig *config); 37 static bool listReqMode(pxConfig *config); 37 38 static bool pendingReqMode(pxConfig *config); 38 39 static bool processedReqMode(pxConfig *config); … … 65 66 MODECASE(PSTAMPTOOL_MODE_MODDATASTORE, moddatastoreMode); 66 67 MODECASE(PSTAMPTOOL_MODE_ADDREQ, addReqMode); 68 MODECASE(PSTAMPTOOL_MODE_LISTREQ, listReqMode); 67 69 MODECASE(PSTAMPTOOL_MODE_PENDINGREQ, pendingReqMode); 68 70 MODECASE(PSTAMPTOOL_MODE_PROCESSEDREQ, processedReqMode); … … 254 256 } 255 257 258 #define MAGIC_STR "$REQ_ID" 259 260 // Replace $REQ_ID with the value of the request id if present in the outFileset 261 262 static bool 263 updateFilesetID(pxConfig *config, psS64 req_id, psString outFileset) 264 { 265 char *magic; 266 267 magic = strcasestr(outFileset, MAGIC_STR); 268 if (magic == NULL) { 269 return true; 270 } 271 272 // find part of the string after the magic 273 char *after = magic + strlen(MAGIC_STR); 274 275 if (*after == 0) { 276 after = NULL; 277 } 278 279 psString converted = NULL; 280 if (magic > outFileset) { 281 int len = magic - outFileset; 282 converted = psStringAlloc(len + 1); 283 strncpy(converted, outFileset, len); 284 converted[len] = 0; 285 } 286 287 psStringAppend(&converted, "%" PRId64, req_id); 288 if (after) { 289 psStringAppend(&converted, after); 290 } 291 292 if (!p_psDBRunQuery(config->dbh, "UPDATE pstampRequest set outFileset = '%s' WHERE req_id = %" PRId64, 293 converted, req_id)) { 294 psError(PS_ERR_UNKNOWN, false, "database error"); 295 return false; 296 } 297 298 return true; 299 } 300 256 301 static bool addReqMode(pxConfig *config) 257 302 { … … 307 352 308 353 psS64 req_id = psDBLastInsertID(config->dbh); 354 if (!updateFilesetID(config, req_id, outFileset)) { 355 psError(PS_ERR_UNKNOWN, false, "failed to update fileset id\n"); 356 return false; 357 } 358 309 359 printf("%" PRId64 "\n", req_id); 310 360 … … 334 384 psStringAppend(&query, " AND %s", whereClause); 335 385 psFree(whereClause); 386 } 387 388 // treat limit == 0 as "no limit" 389 if (limit) { 390 psString limitString = psDBGenerateLimitSQL(limit); 391 psStringAppend(&query, " %s", limitString); 392 psFree(limitString); 393 } 394 395 if (!p_psDBRunQuery(config->dbh, query)) { 396 psError(PS_ERR_UNKNOWN, false, "database error"); 397 psFree(query); 398 return false; 399 } 400 psFree(query); 401 402 psArray *output = p_psDBFetchResult(config->dbh); 403 if (!output) { 404 psError(PS_ERR_UNKNOWN, false, "database error"); 405 return false; 406 } 407 if (!psArrayLength(output)) { 408 psTrace("pstamptool", PS_LOG_INFO, "no rows found"); 409 psFree(output); 410 return true; 411 } 412 413 bool simple = false; 414 { 415 bool status = false; 416 simple = psMetadataLookupBool(&status, config->args, "-simple"); 417 if (!status) { 418 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 419 psFree(output); 420 return false; 421 } 422 } 423 424 // negative simple so the default is true 425 if (!ippdbPrintMetadatas(stdout, output, "pstampRequest", !simple)) { 426 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 427 psFree(output); 428 return false; 429 } 430 431 psFree(output); 432 433 return true; 434 } 435 static bool listReqMode(pxConfig *config) 436 { 437 PS_ASSERT_PTR_NON_NULL(config, false); 438 439 bool status = false; 440 psU64 limit = psMetadataLookupU64(&status, config->args, "-limit"); 441 if (!status) { 442 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit"); 443 return false; 444 } 445 446 psString query = NULL; 447 448 psString req_id = psMetadataLookupStr(&status, config->args, "-req_id"); 449 450 if (req_id) { 451 psStringAppend(&query, 452 "SELECT" 453 " *" 454 " FROM pstampRequest" 455 " WHERE req_id = %s", req_id 456 ); 457 } else { 458 fprintf(stderr, "req_id must be specified\n"); 459 exit (1); 336 460 } 337 461 -
trunk/ippTools/src/pstamptool.h
r16471 r16957 29 29 PSTAMPTOOL_MODE_MODDATASTORE, 30 30 PSTAMPTOOL_MODE_ADDREQ, 31 PSTAMPTOOL_MODE_LISTREQ, 31 32 PSTAMPTOOL_MODE_PENDINGREQ, 32 33 PSTAMPTOOL_MODE_PROCESSEDREQ, -
trunk/ippTools/src/pstamptoolConfig.c
r16931 r16957 89 89 "limit result set to N items", 0); 90 90 psMetadataAddBool(pendingreqArgs, PS_LIST_TAIL, "-simple", 0, 91 "use the simple output format", false); 92 93 // -listreq 94 psMetadata *listreqArgs = psMetadataAlloc(); 95 psMetadataAddStr(listreqArgs, PS_LIST_TAIL, "-req_id", 0, 96 "define req_id", NULL); 97 psMetadataAddU64(listreqArgs, PS_LIST_TAIL, "-limit", 0, 98 "limit result set to N items", 0); 99 psMetadataAddBool(listreqArgs, PS_LIST_TAIL, "-simple", 0, 91 100 "use the simple output format", false); 92 101 … … 165 174 PXOPT_ADD_MODE("-pendingreq", "", PSTAMPTOOL_MODE_PENDINGREQ, pendingreqArgs); 166 175 PXOPT_ADD_MODE("-processedreq", "", PSTAMPTOOL_MODE_PROCESSEDREQ, processedreqArgs); 176 PXOPT_ADD_MODE("-listreq", "", PSTAMPTOOL_MODE_LISTREQ, listreqArgs); 167 177 168 178 PXOPT_ADD_MODE("-addjob", "", PSTAMPTOOL_MODE_ADDJOB, addjobArgs);
Note:
See TracChangeset
for help on using the changeset viewer.
