Changeset 27838 for branches/tap_branches/ippTools/src/pstamptool.c
- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/pstamptool.c (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/ippTools/src
- Property svn:ignore
-
old new 16 16 difftool 17 17 disttool 18 dqstatstool 18 19 faketool 19 20 flatcorr
-
- Property svn:ignore
-
branches/tap_branches/ippTools/src/pstamptool.c
r25793 r27838 51 51 static bool pendingdependentMode(pxConfig *config); 52 52 static bool updatedependentMode(pxConfig *config); 53 static bool revertdependentMode(pxConfig *config); 53 54 54 55 # define MODECASE(caseName, func) \ … … 91 92 MODECASE(PSTAMPTOOL_MODE_PENDINGDEPENDENT, pendingdependentMode); 92 93 MODECASE(PSTAMPTOOL_MODE_UPDATEDEPENDENT, updatedependentMode); 94 MODECASE(PSTAMPTOOL_MODE_REVERTDEPENDENT, revertdependentMode); 93 95 default: 94 96 psAbort("invalid option (this should not happen)"); … … 116 118 PS_ASSERT_PTR_NON_NULL(config, false); 117 119 118 PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false); 119 PXOPT_LOOKUP_STR(outProduct, config->args, "-out_product", true, false); 120 PXOPT_LOOKUP_STR(lastFileset, config->args, "-last_fileset", false, false); 121 PXOPT_LOOKUP_STR(state, config->args, "-state", false, false); 120 PXOPT_LOOKUP_STR(uri, config->args, "-set_uri", true, false); 121 PXOPT_LOOKUP_STR(outProduct, config->args, "-set_out_product", true, false); 122 PXOPT_LOOKUP_STR(lastFileset, config->args, "-set_last_fileset", false, false); 123 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 124 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); 125 PXOPT_LOOKUP_S32(pollInterval, config->args, "-set_poll_interval",false, false); 122 126 123 127 if (!pstampDataStoreInsert(config->dbh, … … 125 129 state, 126 130 lastFileset, 131 NULL, // timestamp 132 label, // label 127 133 outProduct, 128 uri 134 uri, 135 pollInterval 129 136 )) { 130 137 psError(PS_ERR_UNKNOWN, false, "database error"); … … 142 149 PXOPT_COPY_S64(config->args, where, "-ds_id", "ds_id", "=="); 143 150 151 PXOPT_LOOKUP_BOOL(ready, config->args, "-ready", false); 144 152 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 145 153 146 154 psString query = pxDataGet("pstamptool_datastore.sql"); 147 155 if (!query) { 148 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");156 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 149 157 return false; 150 158 } … … 156 164 } 157 165 psFree(where); 166 if (ready) { 167 psStringAppend(&query, " %s", "\nAND TIMESTAMPDIFF(SECOND, timestamp, now()) > pollInterval"); 168 } 158 169 159 170 if (!p_psDBRunQuery(config->dbh, query)) { … … 189 200 190 201 PXOPT_LOOKUP_S64(ds_id, config->args, "-ds_id", true, false); 191 PXOPT_LOOKUP_STR(lastFileset, config->args, "-last_fileset", false, false); 192 PXOPT_LOOKUP_STR(state, config->args, "-state", false, false); 193 194 if (!state && !lastFileset) { 195 psError(PS_ERR_UNKNOWN, true, "at least one of -last_fileset or -state is required"); 196 return false; 197 } 198 199 char *query = psStringCopy ("UPDATE pstampDataStore SET"); 200 bool needComma = false; 201 202 PXOPT_LOOKUP_STR(lastFileset, config->args, "-set_last_fileset", false, false); 203 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 204 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); 205 PXOPT_LOOKUP_S32(pollInterval, config->args, "-set_poll_interval", false, false); 206 PXOPT_LOOKUP_BOOL(update_timestamp, config->args, "-update_timestamp", false); 207 208 if (!state && !lastFileset && !pollInterval && !update_timestamp && !label) { 209 psError(PS_ERR_UNKNOWN, true, "at least one of -last_fileset or -set_state is required"); 210 return false; 211 } 212 213 char *query = psStringCopy ("UPDATE pstampDataStore SET timestamp = CURRENT_TIMESTAMP() "); 214 202 215 if (lastFileset) { 203 psStringAppend(&query, " lastFileset = '%s'", lastFileset); 204 needComma = true; 216 psStringAppend(&query, " , lastFileset = '%s'", lastFileset); 205 217 } 206 218 207 219 if (state) { 208 psStringAppend(&query, "%s state = '%s'", needComma ? "," : " ", state); 209 needComma = true; // be ready in case we add another field 210 } 211 220 psStringAppend(&query, ", state = '%s'", state); 221 } 222 223 if (label) { 224 psStringAppend(&query, ", label = '%s'", label); 225 } 226 227 if (pollInterval) { 228 psStringAppend(&query, ", pollInterval = %d", pollInterval); 229 } 230 212 231 psStringAppend(&query, " WHERE ds_id = %" PRId64, ds_id); 213 232 … … 220 239 psU64 affected = psDBAffectedRows(config->dbh); 221 240 if (affected != 1) { 222 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 241 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 223 242 PRIu64 " rows were modified", affected); 224 243 return false; … … 245 264 label, 246 265 NULL, // outProduct 247 uri, 248 0 // fault 266 uri, 267 0 // fault 249 268 )) { 250 269 psError(PS_ERR_UNKNOWN, false, "failed to insert request"); … … 265 284 psMetadata *where = psMetadataAlloc(); 266 285 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 286 pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE"); 267 287 268 288 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 271 291 psString query = pxDataGet("pstamptool_pendingreq.sql"); 272 292 if (!query) { 273 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");293 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 274 294 return false; 275 295 } … … 342 362 psFree(whereClause); 343 363 psFree(where); 344 364 345 365 // treat limit == 0 as "no limit" 346 366 if (limit) { … … 365 385 psTrace("pstamptool", PS_LOG_INFO, "request not found"); 366 386 // This causes main to exit with PS_EXIT_DATA_ERROR which the script is looking for 367 psError(PXTOOLS_ERR_ DATA, true, "request not found");387 psError(PXTOOLS_ERR_CONFIG, true, "request not found"); 368 388 psFree(output); 369 389 // we return false so that the caller can determine that a request does not exist … … 387 407 PS_ASSERT_PTR_NON_NULL(config, false); 388 408 409 psMetadata *where = psMetadataAlloc(); 410 pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE"); 411 389 412 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 390 413 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 391 414 392 415 psString query = pxDataGet("pstamptool_completedreq.sql"); 416 417 if (psListLength(where->list)) { 418 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 419 psStringAppend(&query, " AND %s", whereClause); 420 psFree(whereClause); 421 } 422 psFree(where); 393 423 394 424 // treat limit == 0 as "no limit" … … 436 466 PXOPT_LOOKUP_STR(state, config->args, "-state", false, false); 437 467 PXOPT_LOOKUP_STR(outProduct, config->args, "-outProduct", false, false); 438 PXOPT_LOOKUP_S TR(fault,config->args, "-fault", false, false);439 PXOPT_LOOKUP_STR(uri, config->args, "-uri", false, false);440 PXOPT_LOOKUP_STR(name, config->args, "-name", false, false);468 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 469 PXOPT_LOOKUP_STR(uri, config->args, "-uri", false, false); 470 PXOPT_LOOKUP_STR(name, config->args, "-name", false, false); 441 471 PXOPT_LOOKUP_STR(reqType, config->args, "-reqType", false, false); 442 472 … … 454 484 } 455 485 if (fault) { 456 psStringAppend(&query, "%c fault = % s", c, fault);486 psStringAppend(&query, "%c fault = %d", c, fault); 457 487 c = ','; 458 488 } … … 485 515 // note zero is not an error 486 516 if (affected > 1) { 487 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 517 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 488 518 PRIu64 " rows were modified", affected); 489 519 return false; … … 500 530 501 531 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 502 PXOPT_COPY_S64(config->args, where, "-fault", " req_id", "==");532 PXOPT_COPY_S64(config->args, where, "-fault", "fault", "=="); 503 533 PXOPT_COPY_STR(config->args, where, "-state", "pstampRequest.state", "=="); 534 pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "LIKE"); 504 535 505 536 if (!psListLength(where->list)) { 506 537 psFree(where); 507 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");538 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 508 539 return false; 509 540 } … … 525 556 query = pxDataGet("pstamptool_revertreq.sql"); 526 557 psStringAppend(&query, " AND %s", whereClause); 527 558 528 559 psFree(whereClause); 529 560 … … 555 586 // unless the job is being inserted with stop state require outputBase 556 587 if (strcmp(stateString, "stop") && !outputBase) { 557 psError(PS_ERR_UNKNOWN, true, "-outputBase is required");558 return false;588 psError(PS_ERR_UNKNOWN, true, "-outputBase is required"); 589 return false; 559 590 } 560 591 561 592 // default value for job_type is defined in pstamptoolConfig.c 562 593 if (!strcmp(job_type, "get_image") || !strcmp(job_type, "detect_query") || !strcmp(job_type, "none")) { 563 stampJob = false;594 stampJob = false; 564 595 } else if (!strcmp(job_type, "stamp")) { 565 stampJob = true;596 stampJob = true; 566 597 } else { 567 psError(PS_ERR_UNKNOWN, false, "unknown value for -job_type: %s", job_type);568 return false;569 } 570 if (!pstampJobInsert(config->dbh, 598 psError(PS_ERR_UNKNOWN, false, "unknown value for -job_type: %s", job_type); 599 return false; 600 } 601 if (!pstampJobInsert(config->dbh, 571 602 0, // job_id 572 603 req_id, 573 rownum, 574 stateString, 575 job_type, 576 fault, 577 exp_id, 604 rownum, 605 stateString, 606 job_type, 607 fault, 608 exp_id, 578 609 outputBase, 579 610 options, … … 586 617 psU64 affected = psDBAffectedRows(config->dbh); 587 618 if (affected != 1) { 588 psError(PS_ERR_UNKNOWN, false, 619 psError(PS_ERR_UNKNOWN, false, 589 620 "should have affected one row but %" PRIu64 " rows were modified", 590 621 affected); … … 617 648 psString query = pxDataGet("pstamptool_listjob.sql"); 618 649 if (!query) { 619 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");650 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 620 651 return false; 621 652 } … … 674 705 PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "=="); 675 706 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 707 pxAddLabelSearchArgs(config, where, "-label", "label", "LIKE"); 708 676 709 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 677 710 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); … … 679 712 psString query = pxDataGet("pstamptool_pendingjob.sql"); 680 713 if (!query) { 681 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");714 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 682 715 return false; 683 716 } … … 685 718 // use psDBGenerateWhereSQL because the SQL yields an intermediate table 686 719 if (psListLength(where->list)) { 687 psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampJob");720 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 688 721 psStringAppend(&query, " AND %s", whereClause); 689 722 psFree(whereClause); … … 732 765 PS_ASSERT_PTR_NON_NULL(config, false); 733 766 734 PXOPT_LOOKUP_S64(job_id, config->args, "-job_id", true, false); 767 PXOPT_LOOKUP_S64(job_id, config->args, "-job_id", false, false); 768 PXOPT_LOOKUP_S64(dep_id, config->args, "-dep_id", false, false); 769 770 if (!job_id && !dep_id) { 771 psError(PS_ERR_UNKNOWN, true, "at least -job_id or -dep_id is required"); 772 return false; 773 } 735 774 PXOPT_LOOKUP_STR(state, config->args, "-state", true, false); 736 PXOPT_LOOKUP_STR(fault, config->args, "-fault", false, false); 775 PXOPT_LOOKUP_S32(fault, config->args, "-fault", false, false); 776 777 psMetadata *where = psMetadataAlloc(); 778 779 PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "=="); 780 PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "=="); 737 781 738 782 psString faultStr = NULL; … … 740 784 faultStr = psStringCopy(""); 741 785 } else { 742 psStringAppend(&faultStr, ", fault = '%s'", fault); 743 } 744 745 char *query ="UPDATE pstampJob" 746 " SET state = '%s' %s" 747 " WHERE job_id = %" PRId64; 748 749 if (!p_psDBRunQueryF(config->dbh, query, state, faultStr, job_id)) { 786 psStringAppend(&faultStr, "\n, pstampJob.fault = %d", fault); 787 } 788 789 psString query = pxDataGet("pstamptool_updatejob.sql"); 790 791 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 792 psStringAppend(&query, " WHERE %s", whereClause); 793 psFree(whereClause); 794 psFree(where); 795 796 if (!p_psDBRunQueryF(config->dbh, query, state, faultStr)) { 750 797 psError(PS_ERR_UNKNOWN, false, "database error"); 751 798 psFree(query); … … 753 800 } 754 801 psFree(faultStr); 802 psFree(query); 755 803 756 804 psU64 affected = psDBAffectedRows(config->dbh); 757 if (affected != 1) { 758 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 759 PRIu64 " rows were modified", affected); 760 return false; 761 } 805 psLogMsg("pstamptool", PS_LOG_INFO, "Updated %" PRIu64 " pstampJobs", affected); 762 806 763 807 return true; … … 772 816 PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "=="); 773 817 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 774 PXOPT_COPY_S64(config->args, where, "-fault", " fault", "==");818 PXOPT_COPY_S64(config->args, where, "-fault", "pstampJob.fault", "=="); 775 819 PXOPT_COPY_S64(config->args, where, "-req_id_min", "req_id", ">="); 820 pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "LIKE"); 821 776 822 PXOPT_LOOKUP_BOOL(all, config->args, "-all", false); 777 823 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 824 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 825 826 // By default only revert faults < 10 which are our "ipp exit codes" 827 // codes larger than that are the pstamp request interface. 828 // Don't fault those unless -fault waa provided 829 psString faultClause = ""; 830 if (!fault) { 831 faultClause = " \nAND (pstampJob.fault < 10)"; 832 } 778 833 779 834 psString query = pxDataGet("pstamptool_revertjob.sql"); 780 835 if (!psListLength(where->list) && !all) { 781 836 psFree(where); 782 psError(PXTOOLS_ERR_ DATA, false, "search parameters or -all are required");837 psError(PXTOOLS_ERR_CONFIG, false, "search parameters or -all are required"); 783 838 return false; 784 839 } 785 840 if (psListLength(where->list)) { 786 psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampJob");841 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 787 842 psStringAppend(&query, " AND %s", whereClause); 788 843 psFree(whereClause); 789 844 } 790 845 psFree(where); 791 792 if (!p_psDBRunQuery (config->dbh, query)) {846 847 if (!p_psDBRunQueryF(config->dbh, query, faultClause)) { 793 848 psError(PS_ERR_UNKNOWN, false, "database error"); 794 849 return false; … … 837 892 psString query = pxDataGet("pstamptool_project.sql"); 838 893 if (!query) { 839 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");894 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 840 895 return false; 841 896 } … … 883 938 884 939 char *query = psStringCopy ("UPDATE pstampProject SET"); 885 940 886 941 psStringAppend(&query, " state = '%s'", state); 887 942 888 943 psStringAppend(&query, " WHERE proj_id = %" PRId64, proj_id); 889 944 … … 896 951 psU64 affected = psDBAffectedRows(config->dbh); 897 952 if (affected != 1) { 898 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 953 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 899 954 PRIu64 " rows were modified", affected); 900 955 return false; … … 910 965 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false); 911 966 PXOPT_LOOKUP_S64(stage_id, config->args, "-stage_id", true, false); 967 PXOPT_LOOKUP_STR(component, config->args, "-component", true, false); 912 968 PXOPT_LOOKUP_STR(imagedb, config->args, "-imagedb", true, false); 913 PXOPT_LOOKUP_STR(rlabel, config->args, "-rlabel", false, false);914 PXOPT_LOOKUP_BOOL(n o_magic, config->args, "-no_magic", false);969 PXOPT_LOOKUP_STR(rlabel, config->args, "-rlabel", true, false); 970 PXOPT_LOOKUP_BOOL(need_magic, config->args, "-need_magic", false); 915 971 PXOPT_LOOKUP_BOOL(no_create, config->args, "-no_create", false); 916 972 917 psString query = pxDataGet("pstamptool_pendingdependent.sql"); 973 psMetadata *where = psMetadataAlloc(); 974 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 975 PXOPT_COPY_STR(config->args, where, "-imagedb", "imagedb", "=="); 976 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); 977 PXOPT_COPY_STR(config->args, where, "-component", "component", "=="); 978 979 // start a transaction eraly so it will contain any row level locks 980 if (!psDBTransaction(config->dbh)) { 981 psError(PS_ERR_UNKNOWN, false, "database error"); 982 return false; 983 } 984 985 psString query = pxDataGet("pstamptool_getdependent.sql"); 918 986 if (!query) { 919 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 920 return false; 921 } 987 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 988 return false; 989 } 990 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 991 if (!no_create) { 992 // This will lock the row until the transaction is committed 993 psStringAppend(&query, " AND %s FOR UPDATE", whereClause); 994 } else { 995 psStringAppend(&query, " AND %s", whereClause); 996 } 997 psFree(whereClause); 998 psFree(where); 999 922 1000 if (!p_psDBRunQuery(config->dbh, query)) { 923 1001 psError(PS_ERR_UNKNOWN, false, "database error"); … … 937 1015 if (!dep_id) { 938 1016 psError(PS_ERR_UNKNOWN, false, "database error"); 1017 psFree(output); 939 1018 return false; 940 1019 } 941 1020 printf("%" PRId64 "\n", dep_id); 1021 psFree(output); 1022 if (!psDBRollback(config->dbh)) { 1023 psError(PS_ERR_UNKNOWN, false, "database error"); 1024 } 942 1025 return true; 943 1026 } 944 1027 if (no_create) { 1028 if (!psDBRollback(config->dbh)) { 1029 psError(PS_ERR_UNKNOWN, false, "database error"); 1030 return false; 1031 } 945 1032 return true; 946 1033 } 947 1034 // no existing dependent that matches, insert one 1035 // Since we have multiple processes running jobs we have a 1036 // race condition here so that's why we need to lock the table 948 1037 949 1038 if (!pstampDependentInsert( … … 953 1042 stage, 954 1043 stage_id, 1044 component, 955 1045 imagedb, 956 1046 rlabel, 957 no_magic 1047 need_magic, 1048 0 // fault 958 1049 )) { 1050 if (!psDBRollback(config->dbh)) { 1051 psError(PS_ERR_UNKNOWN, false, "database error"); 1052 } 959 1053 psError(PS_ERR_UNKNOWN, false, "failed to insert pstampDependent"); 960 1054 return false; 961 1055 } 962 1056 1057 // if we try and get this after commit zero is returned 963 1058 psS64 dep_id = psDBLastInsertID(config->dbh); 1059 if (!dep_id) { 1060 psError(PS_ERR_UNKNOWN, false, "psDBLastInsertID returned NULL"); 1061 if (!psDBRollback(config->dbh)) { 1062 psError(PS_ERR_UNKNOWN, false, "database error"); 1063 } 1064 return false; 1065 } 1066 1067 if (!psDBCommit(config->dbh)) { 1068 // rollback 1069 if (!psDBRollback(config->dbh)) { 1070 psError(PS_ERR_UNKNOWN, false, "database error"); 1071 } 1072 psError(PS_ERR_UNKNOWN, false, "database error"); 1073 return false; 1074 } 964 1075 965 1076 printf("%" PRId64 "\n", dep_id); … … 973 1084 974 1085 psMetadata *where = psMetadataAlloc(); 1086 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 1087 PXOPT_COPY_STR(config->args, where, "-imagedb", "imagedb", "=="); 1088 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); 1089 PXOPT_COPY_STR(config->args, where, "-rlabel", "rlabel", "=="); 1090 pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "=="); 975 1091 976 1092 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 979 1095 psString query = pxDataGet("pstamptool_pendingdependent.sql"); 980 1096 if (!query) { 981 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1097 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 982 1098 return false; 983 1099 } 984 1100 985 1101 if (psListLength(where->list)) { 986 psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampDependent");1102 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 987 1103 psStringAppend(&query, " AND %s", whereClause); 988 1104 psFree(whereClause); … … 1031 1147 1032 1148 PXOPT_LOOKUP_S64(dep_id, config->args, "-dep_id", true, false); 1033 PXOPT_LOOKUP_STR(state, config->args, "-set_state", true, false); 1034 1035 char *query ="UPDATE pstampDependent" 1036 " SET state = '%s'" 1037 " WHERE dep_id = %" PRId64; 1038 1039 if (!p_psDBRunQueryF(config->dbh, query, state, dep_id)) { 1149 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1150 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 1151 1152 if (!fault && !state) { 1153 psError(PS_ERR_UNKNOWN, true, "at least one of -set_state or fault is required"); 1154 return false; 1155 } 1156 psString query = psStringCopy("UPDATE pstampDependent SET"); 1157 bool needComma = false; 1158 if (state) { 1159 psStringAppend(&query, " state = '%s'", state); 1160 needComma = true; 1161 } 1162 if (fault) { 1163 psStringAppend(&query, "%s fault = %d", needComma ? ", " : "", fault); 1164 needComma = true; 1165 } 1166 psStringAppend(&query, " WHERE dep_id = %" PRId64, dep_id); 1167 1168 if (!p_psDBRunQuery(config->dbh, query)) { 1040 1169 psError(PS_ERR_UNKNOWN, false, "database error"); 1041 1170 psFree(query); … … 1045 1174 psU64 affected = psDBAffectedRows(config->dbh); 1046 1175 if (affected != 1) { 1047 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 1176 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 1048 1177 PRIu64 " rows were modified", affected); 1049 1178 return false; … … 1052 1181 return true; 1053 1182 } 1183 static bool revertdependentMode(pxConfig *config) 1184 { 1185 PS_ASSERT_PTR_NON_NULL(config, false); 1186 1187 psMetadata *where = psMetadataAlloc(); 1188 PXOPT_COPY_S64(config->args, where, "-fault", "pstampDependent.fault", "=="); 1189 PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "=="); 1190 pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "=="); 1191 1192 if (!psListLength(where->list)) { 1193 psFree(where); 1194 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1195 return false; 1196 } 1197 psString query = pxDataGet("pstamptool_revertdependent.sql"); 1198 if (!query) { 1199 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1200 return false; 1201 } 1202 1203 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1204 psStringAppend(&query, " AND %s", whereClause); 1205 psFree(whereClause); 1206 psFree(where); 1207 1208 if (!p_psDBRunQuery(config->dbh, query)) { 1209 psError(PS_ERR_UNKNOWN, false, "database error"); 1210 psFree(query); 1211 return false; 1212 } 1213 1214 return true; 1215 }
Note:
See TracChangeset
for help on using the changeset viewer.
