Changeset 18526 for trunk/ippTools/src/magictool.c
- Timestamp:
- Jul 14, 2008, 6:21:12 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/magictool.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/magictool.c
r18525 r18526 43 43 static bool tomaskMode(pxConfig *config); 44 44 static bool addmaskMode(pxConfig *config); 45 static bool maskMode(pxConfig *config); 45 46 46 47 static bool setmagicRunState(pxConfig *config, psS64 magic_id, const char *state); … … 77 78 MODECASE(MAGICTOOL_MODE_TOMASK, tomaskMode); 78 79 MODECASE(MAGICTOOL_MODE_ADDMASK, addmaskMode); 80 MODECASE(MAGICTOOL_MODE_MASK, maskMode); 79 81 default: 80 82 psAbort("invalid option (this should not happen)"); … … 878 880 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 879 881 882 if (!psDBTransaction(config->dbh)) { 883 psError(PS_ERR_UNKNOWN, false, "database error"); 884 return false; 885 } 886 880 887 if (!magicMaskInsert(config->dbh, 881 888 (psS64)atoll(magic_id), … … 887 894 return false; 888 895 } 896 897 // Set the magicRun state 898 psString query = pxDataGet("magictool_addmask.sql"); 899 if (!query) { 900 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 901 return false; 902 } 903 904 // Add "magic_id = value" 905 psString whereClause = psDBGenerateWhereConditionSQL(config->where, NULL); 906 psStringAppend(&query, " AND %s", whereClause); 907 psFree(whereClause); 908 909 if (!p_psDBRunQuery(config->dbh, query)) { 910 psError(PS_ERR_UNKNOWN, false, "database error"); 911 psFree(query); 912 return false; 913 } 914 psFree(query); 915 916 if (!psDBCommit(config->dbh)) { 917 psError(PS_ERR_UNKNOWN, false, "database error"); 918 return false; 919 } 920 921 return true; 922 } 923 924 925 static bool maskMode(pxConfig *config) 926 { 927 PS_ASSERT_PTR_NON_NULL(config, false); 928 929 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 930 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 931 932 psString query = pxDataGet("magictool_mask.sql"); 933 if (!query) { 934 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 935 return false; 936 } 937 938 if (config->where) { 939 psString whereClause = psDBGenerateWhereConditionSQL(config->where, NULL); 940 psStringAppend(&query, " AND %s", whereClause); 941 psFree(whereClause); 942 } 943 944 // treat limit == 0 as "no limit" 945 if (limit) { 946 psString limitString = psDBGenerateLimitSQL(limit); 947 psStringAppend(&query, " %s", limitString); 948 psFree(limitString); 949 } 950 951 if (!p_psDBRunQuery(config->dbh, query)) { 952 psError(PS_ERR_UNKNOWN, false, "database error"); 953 psFree(query); 954 return false; 955 } 956 psFree(query); 957 958 psArray *output = p_psDBFetchResult(config->dbh); 959 if (!output) { 960 psErrorCode err = psErrorCodeLast(); 961 switch (err) { 962 case PS_ERR_DB_CLIENT: 963 psError(PXTOOLS_ERR_SYS, false, "database error"); 964 case PS_ERR_DB_SERVER: 965 psError(PXTOOLS_ERR_PROG, false, "database error"); 966 default: 967 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 968 } 969 970 return false; 971 } 972 if (!psArrayLength(output)) { 973 psTrace("magictool", PS_LOG_INFO, "no rows found"); 974 psFree(output); 975 return true; 976 } 977 978 if (psArrayLength(output)) { 979 // negative simple so the default is true 980 if (!ippdbPrintMetadatas(stdout, output, "magicNode", !simple)) { 981 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 982 psFree(output); 983 return false; 984 } 985 } 986 987 psFree(output); 889 988 890 989 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
