Changeset 27740 for trunk/ippTools/src/pstamptool.c
- Timestamp:
- Apr 23, 2010, 11:23:02 AM (16 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pstamptool.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pstamptool.c
r27282 r27740 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)"); … … 464 466 PXOPT_LOOKUP_STR(state, config->args, "-state", false, false); 465 467 PXOPT_LOOKUP_STR(outProduct, config->args, "-outProduct", false, false); 466 PXOPT_LOOKUP_S TR(fault, config->args, "-fault", false, false);468 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 467 469 PXOPT_LOOKUP_STR(uri, config->args, "-uri", false, false); 468 470 PXOPT_LOOKUP_STR(name, config->args, "-name", false, false); … … 482 484 } 483 485 if (fault) { 484 psStringAppend(&query, "%c fault = % s", c, fault);486 psStringAppend(&query, "%c fault = %d", c, fault); 485 487 c = ','; 486 488 } … … 763 765 PS_ASSERT_PTR_NON_NULL(config, false); 764 766 765 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 } 766 774 PXOPT_LOOKUP_STR(state, config->args, "-state", true, false); 767 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", "=="); 768 781 769 782 psString faultStr = NULL; … … 771 784 faultStr = psStringCopy(""); 772 785 } else { 773 psStringAppend(&faultStr, ", fault = '%s'", fault); 774 } 775 776 char *query ="UPDATE pstampJob" 777 " SET state = '%s' %s" 778 " WHERE job_id = %" PRId64; 779 780 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)) { 781 797 psError(PS_ERR_UNKNOWN, false, "database error"); 782 798 psFree(query); … … 784 800 } 785 801 psFree(faultStr); 802 psFree(query); 786 803 787 804 psU64 affected = psDBAffectedRows(config->dbh); 788 if (affected != 1) { 789 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 790 PRIu64 " rows were modified", affected); 791 return false; 792 } 805 psLogMsg("pstamptool", PS_LOG_INFO, "Updated %" PRIu64 " pstampJobs", affected); 793 806 794 807 return true; … … 952 965 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false); 953 966 PXOPT_LOOKUP_S64(stage_id, config->args, "-stage_id", true, false); 967 PXOPT_LOOKUP_STR(component, config->args, "-component", true, false); 954 968 PXOPT_LOOKUP_STR(imagedb, config->args, "-imagedb", true, false); 955 969 PXOPT_LOOKUP_STR(rlabel, config->args, "-rlabel", false, false); 956 PXOPT_LOOKUP_BOOL(n o_magic, config->args, "-no_magic", false);970 PXOPT_LOOKUP_BOOL(need_magic, config->args, "-need_magic", false); 957 971 PXOPT_LOOKUP_BOOL(no_create, config->args, "-no_create", false); 958 972 … … 961 975 PXOPT_COPY_STR(config->args, where, "-imagedb", "imagedb", "=="); 962 976 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); 977 PXOPT_COPY_STR(config->args, where, "-component", "component", "=="); 963 978 964 979 // start a transaction eraly so it will contain any row level locks … … 973 988 return false; 974 989 } 975 psString whereClause = psDBGenerateWhere SQL(where, "WHERE");990 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 976 991 if (!no_create) { 977 992 // This will lock the row until the transaction is committed 978 psStringAppend(&query, " %s FOR UPDATE", whereClause);993 psStringAppend(&query, " AND %s FOR UPDATE", whereClause); 979 994 } else { 980 psStringAppend(&query, " %s", whereClause);995 psStringAppend(&query, " AND %s", whereClause); 981 996 } 982 997 psFree(whereClause); … … 1027 1042 stage, 1028 1043 stage_id, 1044 component, 1029 1045 imagedb, 1030 1046 rlabel, 1031 no_magic 1047 need_magic, 1048 0 // fault 1032 1049 )) { 1033 1050 if (!psDBRollback(config->dbh)) { … … 1038 1055 } 1039 1056 1057 // if we try and get this after commit zero is returned 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 1040 1067 if (!psDBCommit(config->dbh)) { 1041 1068 // rollback … … 1047 1074 } 1048 1075 1049 psS64 dep_id = psDBLastInsertID(config->dbh);1050 1076 printf("%" PRId64 "\n", dep_id); 1051 1077 … … 1058 1084 1059 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", "=="); 1060 1091 1061 1092 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 1069 1100 1070 1101 if (psListLength(where->list)) { 1071 psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampDependent");1102 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1072 1103 psStringAppend(&query, " AND %s", whereClause); 1073 1104 psFree(whereClause); … … 1116 1147 1117 1148 PXOPT_LOOKUP_S64(dep_id, config->args, "-dep_id", true, false); 1118 PXOPT_LOOKUP_STR(state, config->args, "-set_state", true, false); 1119 1120 char *query ="UPDATE pstampDependent" 1121 " SET state = '%s'" 1122 " WHERE dep_id = %" PRId64; 1123 1124 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)) { 1125 1169 psError(PS_ERR_UNKNOWN, false, "database error"); 1126 1170 psFree(query); … … 1137 1181 return true; 1138 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", "req_id", "=="); 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 = psDBGenerateWhereSQL(where, NULL); 1204 psStringAppend(&query, " %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.
