Changeset 25793 for trunk/ippTools/src/pstamptool.c
- Timestamp:
- Oct 7, 2009, 1:05:22 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pstamptool.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pstamptool.c
r25711 r25793 48 48 static bool projectMode(pxConfig *config); 49 49 static bool modprojectMode(pxConfig *config); 50 static bool getdependentMode(pxConfig *config); 51 static bool pendingdependentMode(pxConfig *config); 52 static bool updatedependentMode(pxConfig *config); 50 53 51 54 # define MODECASE(caseName, func) \ … … 85 88 MODECASE(PSTAMPTOOL_MODE_MODPROJECT, modprojectMode); 86 89 MODECASE(PSTAMPTOOL_MODE_PROJECT, projectMode); 90 MODECASE(PSTAMPTOOL_MODE_GETDEPENDENT, getdependentMode); 91 MODECASE(PSTAMPTOOL_MODE_PENDINGDEPENDENT, pendingdependentMode); 92 MODECASE(PSTAMPTOOL_MODE_UPDATEDEPENDENT, updatedependentMode); 87 93 default: 88 94 psAbort("invalid option (this should not happen)"); … … 545 551 PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false); 546 552 PXOPT_LOOKUP_S64(options, config->args, "-options", false, false); 553 PXOPT_LOOKUP_S64(dep_id, config->args, "-dep_id", false, false); 547 554 548 555 // unless the job is being inserted with stop state require outputBase … … 570 577 exp_id, 571 578 outputBase, 572 options 579 options, 580 dep_id 573 581 )) { 574 582 psError(PS_ERR_UNKNOWN, false, "database error"); … … 896 904 } 897 905 906 static bool getdependentMode(pxConfig *config) 907 { 908 PS_ASSERT_PTR_NON_NULL(config, false); 909 910 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false); 911 PXOPT_LOOKUP_S64(stage_id, config->args, "-stage_id", true, false); 912 PXOPT_LOOKUP_STR(imagedb, config->args, "-imagedb", true, false); 913 PXOPT_LOOKUP_STR(rlabel, config->args, "-rlabel", false, false); 914 PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false); 915 PXOPT_LOOKUP_BOOL(no_create, config->args, "-no_create", false); 916 917 psString query = pxDataGet("pstamptool_pendingdependent.sql"); 918 if (!query) { 919 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 920 return false; 921 } 922 if (!p_psDBRunQuery(config->dbh, query)) { 923 psError(PS_ERR_UNKNOWN, false, "database error"); 924 psFree(query); 925 return false; 926 } 927 psFree(query); 928 929 psArray *output = p_psDBFetchResult(config->dbh); 930 if (!output) { 931 psError(PS_ERR_UNKNOWN, false, "database error"); 932 return false; 933 } 934 if (psArrayLength(output)) { 935 psMetadata *dep = output->data[0]; 936 psS64 dep_id = psMetadataLookupS64(NULL, dep, "dep_id"); 937 if (!dep_id) { 938 psError(PS_ERR_UNKNOWN, false, "database error"); 939 return false; 940 } 941 printf("%" PRId64 "\n", dep_id); 942 return true; 943 } 944 if (no_create) { 945 return true; 946 } 947 // no existing dependent that matches, insert one 948 949 if (!pstampDependentInsert( 950 config->dbh, 951 0, // dep_id 952 "new", // state 953 stage, 954 stage_id, 955 imagedb, 956 rlabel, 957 no_magic 958 )) { 959 psError(PS_ERR_UNKNOWN, false, "failed to insert pstampDependent"); 960 return false; 961 } 962 963 psS64 dep_id = psDBLastInsertID(config->dbh); 964 965 printf("%" PRId64 "\n", dep_id); 966 967 return true; 968 } 969 970 static bool pendingdependentMode(pxConfig *config) 971 { 972 PS_ASSERT_PTR_NON_NULL(config, false); 973 974 psMetadata *where = psMetadataAlloc(); 975 976 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 977 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 978 979 psString query = pxDataGet("pstamptool_pendingdependent.sql"); 980 if (!query) { 981 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 982 return false; 983 } 984 985 if (psListLength(where->list)) { 986 psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampDependent"); 987 psStringAppend(&query, " AND %s", whereClause); 988 psFree(whereClause); 989 } 990 psFree(where); 991 992 // treat limit == 0 as "no limit" 993 if (limit) { 994 psString limitString = psDBGenerateLimitSQL(limit); 995 psStringAppend(&query, " %s", limitString); 996 psFree(limitString); 997 } 998 999 if (!p_psDBRunQuery(config->dbh, query)) { 1000 psError(PS_ERR_UNKNOWN, false, "database error"); 1001 psFree(query); 1002 return false; 1003 } 1004 psFree(query); 1005 1006 psArray *output = p_psDBFetchResult(config->dbh); 1007 if (!output) { 1008 psError(PS_ERR_UNKNOWN, false, "database error"); 1009 return false; 1010 } 1011 if (!psArrayLength(output)) { 1012 psTrace("pstamptool", PS_LOG_INFO, "no rows found"); 1013 psFree(output); 1014 return true; 1015 } 1016 1017 // negative simple so the default is true 1018 if (!ippdbPrintMetadatas(stdout, output, "pstampDependent", !simple)) { 1019 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1020 psFree(output); 1021 return false; 1022 } 1023 1024 psFree(output); 1025 1026 return true; 1027 } 1028 static bool updatedependentMode(pxConfig *config) 1029 { 1030 PS_ASSERT_PTR_NON_NULL(config, false); 1031 1032 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)) { 1040 psError(PS_ERR_UNKNOWN, false, "database error"); 1041 psFree(query); 1042 return false; 1043 } 1044 1045 psU64 affected = psDBAffectedRows(config->dbh); 1046 if (affected != 1) { 1047 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 1048 PRIu64 " rows were modified", affected); 1049 return false; 1050 } 1051 1052 return true; 1053 }
Note:
See TracChangeset
for help on using the changeset viewer.
