Changeset 27874 for trunk/ippTools/src/pstamptool.c
- Timestamp:
- May 6, 2010, 1:55:20 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pstamptool.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pstamptool.c
r27856 r27874 40 40 static bool updatereqMode(pxConfig *config); 41 41 static bool revertreqMode(pxConfig *config); 42 static bool pendingcleanupMode(pxConfig *config); 42 43 static bool addjobMode(pxConfig *config); 43 44 static bool listjobMode(pxConfig *config); … … 81 82 MODECASE(PSTAMPTOOL_MODE_UPDATEREQ, updatereqMode); 82 83 MODECASE(PSTAMPTOOL_MODE_REVERTREQ, revertreqMode); 84 MODECASE(PSTAMPTOOL_MODE_PENDINGCLEANUP, pendingcleanupMode); 83 85 MODECASE(PSTAMPTOOL_MODE_ADDJOB, addjobMode); 84 86 MODECASE(PSTAMPTOOL_MODE_LISTJOB, listjobMode); … … 265 267 NULL, // outProduct 266 268 uri, 269 NULL, // outdir 267 270 0 // fault 268 271 )) { … … 341 344 } 342 345 343 static bool listreqMode(pxConfig *config)346 static bool pendingcleanupMode(pxConfig *config) 344 347 { 345 348 PS_ASSERT_PTR_NON_NULL(config, false); … … 347 350 psMetadata *where = psMetadataAlloc(); 348 351 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 349 PXOPT_COPY_S64(config->args, where, "-not_req_id", "req_id", "!="); 350 PXOPT_COPY_STR(config->args, where, "-name", "name", "=="); 351 352 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 352 pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE"); 353 354 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 353 355 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 354 356 355 if (!psListLength(where->list)) { 356 psError(PS_ERR_UNKNOWN, true, "-req_id or -name must be supplied"); 357 return false; 358 } 359 360 psString query = psStringCopy("SELECT * from pstampRequest"); 361 362 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 363 psStringAppend(&query, " WHERE %s", whereClause); 364 psFree(whereClause); 365 psFree(where); 357 psString query = pxDataGet("pstamptool_pendingcleanup.sql"); 358 if (!query) { 359 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 360 return false; 361 } 362 363 if (psListLength(where->list)) { 364 psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampRequest"); 365 psStringAppend(&query, " AND %s", whereClause); 366 psFree(whereClause); 367 } 368 psFree(where); 369 370 psStringAppend(&query, " ORDER BY priority DESC, req_id"); 366 371 367 372 // treat limit == 0 as "no limit" … … 385 390 } 386 391 if (!psArrayLength(output)) { 387 psTrace("pstamptool", PS_LOG_INFO, "request not found"); 388 // This causes main to exit with PS_EXIT_DATA_ERROR which the script is looking for 389 psError(PXTOOLS_ERR_CONFIG, true, "request not found"); 390 psFree(output); 391 // we return false so that the caller can determine that a request does not exist 392 return false; 392 psTrace("pstamptool", PS_LOG_INFO, "no rows found"); 393 psFree(output); 394 return true; 393 395 } 394 396 … … 405 407 } 406 408 407 static bool completedreqMode(pxConfig *config) 408 { 409 PS_ASSERT_PTR_NON_NULL(config, false); 410 411 psMetadata *where = psMetadataAlloc(); 412 pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE"); 413 414 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 409 static bool listreqMode(pxConfig *config) 410 { 411 PS_ASSERT_PTR_NON_NULL(config, false); 412 413 psMetadata *where = psMetadataAlloc(); 414 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 415 PXOPT_COPY_S64(config->args, where, "-not_req_id", "req_id", "!="); 416 PXOPT_COPY_STR(config->args, where, "-name", "name", "=="); 417 418 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 415 419 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 416 420 417 psString query = pxDataGet("pstamptool_completedreq.sql"); 418 419 if (psListLength(where->list)) { 420 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 421 psStringAppend(&query, " AND %s", whereClause); 422 psFree(whereClause); 423 } 424 psFree(where); 425 426 psStringAppend(&query, " ORDER BY priority DESC, req_id"); 421 if (!psListLength(where->list)) { 422 psError(PS_ERR_UNKNOWN, true, "-req_id or -name must be supplied"); 423 return false; 424 } 425 426 psString query = psStringCopy("SELECT * from pstampRequest"); 427 428 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 429 psStringAppend(&query, " WHERE %s", whereClause); 430 psFree(whereClause); 431 psFree(where); 427 432 428 433 // treat limit == 0 as "no limit" … … 438 443 return false; 439 444 } 445 psFree(query); 440 446 441 447 psArray *output = p_psDBFetchResult(config->dbh); … … 444 450 return false; 445 451 } 446 447 452 if (!psArrayLength(output)) { 448 psTrace("pstamptool", PS_LOG_INFO, "no rows found"); 449 psFree(output); 450 return true; 453 psTrace("pstamptool", PS_LOG_INFO, "request not found"); 454 // This causes main to exit with PS_EXIT_DATA_ERROR which the script is looking for 455 psError(PXTOOLS_ERR_CONFIG, true, "request not found"); 456 psFree(output); 457 // we return false so that the caller can determine that a request does not exist 458 return false; 451 459 } 452 460 … … 463 471 } 464 472 473 static bool completedreqMode(pxConfig *config) 474 { 475 PS_ASSERT_PTR_NON_NULL(config, false); 476 477 psMetadata *where = psMetadataAlloc(); 478 pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE"); 479 480 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 481 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 482 483 psString query = pxDataGet("pstamptool_completedreq.sql"); 484 485 if (psListLength(where->list)) { 486 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 487 psStringAppend(&query, " AND %s", whereClause); 488 psFree(whereClause); 489 } 490 psFree(where); 491 492 psStringAppend(&query, " ORDER BY priority DESC, req_id"); 493 494 // treat limit == 0 as "no limit" 495 if (limit) { 496 psString limitString = psDBGenerateLimitSQL(limit); 497 psStringAppend(&query, " %s", limitString); 498 psFree(limitString); 499 } 500 501 if (!p_psDBRunQuery(config->dbh, query)) { 502 psError(PS_ERR_UNKNOWN, false, "database error"); 503 psFree(query); 504 return false; 505 } 506 507 psArray *output = p_psDBFetchResult(config->dbh); 508 if (!output) { 509 psError(PS_ERR_UNKNOWN, false, "database error"); 510 return false; 511 } 512 513 if (!psArrayLength(output)) { 514 psTrace("pstamptool", PS_LOG_INFO, "no rows found"); 515 psFree(output); 516 return true; 517 } 518 519 // negative simple so the default is true 520 if (!ippdbPrintMetadatas(stdout, output, "pstampRequest", !simple)) { 521 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 522 psFree(output); 523 return false; 524 } 525 526 psFree(output); 527 528 return true; 529 } 530 465 531 static bool updatereqMode(pxConfig *config) 466 532 { 467 533 PS_ASSERT_PTR_NON_NULL(config, false); 468 534 469 PXOPT_LOOKUP_S64(req_id, config->args, "-req_id", true, false); 470 PXOPT_LOOKUP_STR(state, config->args, "-state", false, false); 471 PXOPT_LOOKUP_STR(outProduct, config->args, "-outProduct", false, false); 472 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 473 PXOPT_LOOKUP_STR(uri, config->args, "-uri", false, false); 474 PXOPT_LOOKUP_STR(name, config->args, "-name", false, false); 475 PXOPT_LOOKUP_STR(reqType, config->args, "-reqType", false, false); 476 477 psString query = NULL; 478 psStringAppend(&query, "UPDATE pstampRequest SET"); 479 535 // PXOPT_LOOKUP_S64(req_id, config->args, "-req_id", true, false); 536 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 537 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); 538 PXOPT_LOOKUP_STR(outProduct, config->args, "-set_outProduct", false, false); 539 PXOPT_LOOKUP_S16(fault, config->args, "-set_fault", false, false); 540 PXOPT_LOOKUP_STR(uri, config->args, "-set_uri", false, false); 541 PXOPT_LOOKUP_STR(outdir, config->args, "-set_outdir", false, false); 542 PXOPT_LOOKUP_STR(name, config->args, "-set_name", false, false); 543 PXOPT_LOOKUP_STR(reqType, config->args, "-set_reqType", false, false); 544 PXOPT_LOOKUP_BOOL(clearfault,config->args, "-clearfault", false); 545 546 psMetadata *where = psMetadataAlloc(); 547 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 548 PXOPT_COPY_S64(config->args, where, "-req_id_max", "req_id", "<="); 549 PXOPT_COPY_S32(config->args, where, "-fault", "fault", "=="); 550 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 551 pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "LIKE"); 552 if (!psListLength(where->list)) { 553 psFree(where); 554 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 555 return false; 556 } 557 558 psString query = psStringCopy("UPDATE pstampRequest SET"); 559 560 psString stateCheck = NULL; 480 561 char c = ' '; 481 562 if (state) { 482 563 psStringAppend(&query, "%c state = '%s'", c, state); 483 564 c = ','; 565 if (!strcmp(state, "goto_cleaned")) { 566 psStringAppend(&stateCheck, " AND state != 'cleaned'"); 567 } 568 } 569 if (label) { 570 psStringAppend(&query, "%c label = '%s'", c, label); 571 c = ','; 484 572 } 485 573 if (outProduct) { … … 487 575 c = ','; 488 576 } 489 if (fault) { 577 if (outdir) { 578 psStringAppend(&query, "%c outdir = '%s'", c, outdir); 579 c = ','; 580 } 581 if (clearfault) { 582 if (fault) { 583 psError(PXTOOLS_ERR_CONFIG, true, "only one of -fault and -clearfault is allowed"); 584 return false; 585 } 586 psStringAppend(&query, "%c fault = 0", c); 587 c = ','; 588 } else if (fault) { 490 589 psStringAppend(&query, "%c fault = %d", c, fault); 491 590 c = ','; … … 503 602 c = ','; 504 603 } 505 if (!state && !outProduct && !fault && !uri && !name && !reqType) { 506 psError(PS_ERR_UNKNOWN, true, "at least one of state, outProduct, fault, uri, name, and reqType must be specified"); 507 return false; 508 } 509 510 psStringAppend(&query, " WHERE req_id = %" PRId64, req_id); 604 if (c != ',') { 605 psError(PS_ERR_UNKNOWN, true, "at least one set option is required"); 606 return false; 607 } 608 609 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 610 psStringAppend(&query, "\nWHERE %s", whereClause); 611 psFree(whereClause); 612 psFree(where); 613 614 if (stateCheck) { 615 psStringAppend(&query, stateCheck); 616 } 511 617 512 618 if (!p_psDBRunQuery(config->dbh, query)) { … … 516 622 } 517 623 518 psU64 affected = psDBAffectedRows(config->dbh); 519 // note zero is not an error 520 if (affected > 1) { 521 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 522 PRIu64 " rows were modified", affected); 523 return false; 524 } 624 // psU64 affected = psDBAffectedRows(config->dbh); 625 // psLogMsg("pstamptool", PS_LOG_INFO, "Updated %" PRIu64 " pstampRequests", affected); 525 626 526 627 return true; … … 778 879 return false; 779 880 } 780 PXOPT_LOOKUP_STR(state, config->args, "-state", true, false); 781 PXOPT_LOOKUP_S32(fault, config->args, "-fault", false, false); 881 882 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 883 PXOPT_LOOKUP_S32(fault, config->args, "-set_fault", false, false); 884 885 if (!state && !fault) { 886 psError(PS_ERR_UNKNOWN, true, "at least one of -set_state and -set_fault is required"); 887 return false; 888 } 782 889 783 890 psMetadata *where = psMetadataAlloc(); … … 786 893 PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "=="); 787 894 788 psString faultStr = NULL;789 if (!fault) {790 faultStr = psStringCopy("");791 } else {792 psStringAppend(&faultStr, "\n, pstampJob.fault = %d", fault);793 }794 795 895 psString query = pxDataGet("pstamptool_updatejob.sql"); 796 896 897 char c = ' '; 898 if (state) { 899 psStringAppend(&query, "\n %c pstampJob.state = '%s'", c, state); 900 c = ','; 901 } 902 if (fault) { 903 psStringAppend(&query, "\n %c pstampJob.fault = %d", c, fault); 904 c = ','; 905 } 906 797 907 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 798 908 psStringAppend(&query, " WHERE %s", whereClause); … … 800 910 psFree(where); 801 911 802 if (!p_psDBRunQuery F(config->dbh, query, state, faultStr)) {912 if (!p_psDBRunQuery(config->dbh, query)) { 803 913 psError(PS_ERR_UNKNOWN, false, "database error"); 804 914 psFree(query); 805 915 return false; 806 916 } 807 psFree(faultStr);808 917 psFree(query); 809 918 … … 1159 1268 PXOPT_LOOKUP_S64(dep_id, config->args, "-dep_id", true, false); 1160 1269 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1161 PXOPT_LOOKUP_S16(fault, config->args, "- fault", false, false);1270 PXOPT_LOOKUP_S16(fault, config->args, "-set_fault", false, false); 1162 1271 1163 1272 if (!fault && !state) {
Note:
See TracChangeset
for help on using the changeset viewer.
