Changeset 24949 for trunk/ippTools/src/magictool.c
- Timestamp:
- Jul 30, 2009, 4:06:23 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/magictool.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/magictool.c
r24948 r24949 804 804 // treat limit == 0 as "no limit" 805 805 if (limit) { 806 psString limitString = psDBGenerateLimitSQL(limit); 806 // cut limit in half 807 // hack to prevent pending leaf nodes from blocking branch nodes 808 psString limitString = psDBGenerateLimitSQL((limit + 1) / 2); 807 809 psStringAppend(&query, " %s", limitString); 808 810 psFree(limitString); … … 850 852 851 853 // look for tree nodes that need to be processed 852 // XXX: This gets all nodes from all magicRuns that are in 'new'state 853 // That doens't seem particularly efficient 854 query = pxDataGet("magictool_toprocess_tree.sql"); 854 query = pxDataGet("magictool_toprocess_runs.sql"); 855 855 if (!query) { 856 856 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); … … 858 858 } 859 859 860 { 861 psString limitString = psDBGenerateLimitSQL( 100 ); 862 psStringAppend(&query, " %s", limitString); 863 psFree(limitString); 864 } 860 865 861 866 if (!p_psDBRunQueryF(config->dbh, query, whereString ? whereString : "")) { … … 868 873 psFree(query); 869 874 870 psArray *magic Tree= p_psDBFetchResult(config->dbh);871 if (!magic Tree) {875 psArray *magicRuns = p_psDBFetchResult(config->dbh); 876 if (!magicRuns) { 872 877 psErrorCode err = psErrorCodeLast(); 873 878 switch (err) { … … 882 887 return false; 883 888 } 884 if (!psArrayLength(magic Tree)) {889 if (!psArrayLength(magicRuns)) { 885 890 psTrace("magictool", PS_LOG_INFO, "no rows found"); 886 psFree(magic Tree);891 psFree(magicRuns); 887 892 return true; 888 893 } 889 894 890 // entries are ordered by magic_id 891 long index = 0; 892 while (index < psArrayLength(magicTree)) { 893 bool status; 895 query = pxDataGet("magictool_toprocess_tree.sql"); 896 if (!query) { 897 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 898 return false; 899 } 900 901 for (psS64 index = 0; index < psArrayLength(magicRuns); index++) { 894 902 if (limit && (psArrayLength(output) >= limit)) { 895 903 break; 896 904 } 897 psS64 current_magic_id = psMetadataLookupS64(&status, magicTree->data[index], "magic_id"); 905 bool status; 906 psS64 magic_id = psMetadataLookupS64(&status, magicRuns->data[index], "magic_id"); 898 907 if (!status) { 899 908 psAbort("failed to lookup value for magic_id column"); 900 909 } 901 902 // find the end of this block 903 long first = index; 904 long last = index; 905 for (long i = index + 1; i < psArrayLength(magicTree); i++) { 906 psS64 magic_id = psMetadataLookupS64(&status, magicTree->data[i], "magic_id"); 907 if (!status) { 908 psAbort("failed to lookup value for magic_id column"); 910 911 whereString = NULL; 912 psStringAppend(&whereString, "\nAND (magic_id = %" PRId64 ")", magic_id); 913 if (!p_psDBRunQueryF(config->dbh, query, whereString )) { 914 psError(PS_ERR_UNKNOWN, false, "database error"); 915 psFree(whereString); 916 psFree(query); 917 return false; 918 } 919 psFree(whereString); 920 psArray *magicTree = p_psDBFetchResult(config->dbh); 921 if (!magicTree) { 922 psErrorCode err = psErrorCodeLast(); 923 switch (err) { 924 case PS_ERR_DB_CLIENT: 925 psError(PXTOOLS_ERR_SYS, false, "database error"); 926 case PS_ERR_DB_SERVER: 927 psError(PXTOOLS_ERR_PROG, false, "database error"); 928 default: 929 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 909 930 } 910 if (magic_id != current_magic_id) { 911 break; 912 } 913 last = i; 914 } 915 916 index = last + 1; 917 918 psHash *forest = psHashAlloc(last - first + 1); 931 932 return false; 933 } 934 psS64 length = psArrayLength(magicTree); 935 if (!length) { 936 psTrace("magictool", PS_LOG_INFO, "no rows found for magic_id %" PRId64, magic_id); 937 psFree(magicTree); 938 continue; 939 } 940 941 psHash *forest = psHashAlloc(length); 919 942 920 943 // convert the array of metadata into a pxTree structure 921 for (long i = first; i <= last; i++) {944 for (long i = 0; i < length; i++) { 922 945 bool status; 923 946 psString node = psMetadataLookupStr(&status, magicTree->data[i], "node"); … … 944 967 pxTreeCrawl(root, findReadyNodes, output); 945 968 psFree(root); 946 947 } 948 psFree(magicTree); 969 psFree(magicTree); 970 } 949 971 950 972 if (psArrayLength(output)) {
Note:
See TracChangeset
for help on using the changeset viewer.
