Changeset 23970
- Timestamp:
- Apr 24, 2009, 2:24:35 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/magictool.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/magictool.c
r23688 r23970 457 457 psMetadata *where = psMetadataAlloc(); 458 458 PXOPT_COPY_S64(config->args, where, "-magic_id", "magicRun.magic_id", "=="); 459 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");459 pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "=="); 460 460 461 461 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 739 739 psMetadata *where = psMetadataAlloc(); 740 740 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 741 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");741 pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "=="); 742 742 743 743 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 744 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 744 745 745 746 // look for "inputs" that need to processed … … 750 751 } 751 752 752 psString where Clause= NULL;753 psString whereString = NULL; 753 754 if (psListLength(where->list)) { 754 whereClause = psDBGenerateWhereConditionSQL(where, NULL); 755 psStringAppend(&query, " AND %s", whereClause); 755 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 756 psStringAppend(&whereString, "\nAND %s", whereClause); 757 psFree(whereClause); 756 758 } 757 759 psFree(where); 758 760 759 if (!p_psDBRunQuery(config->dbh, query)) { 760 psError(PS_ERR_UNKNOWN, false, "database error"); 761 // treat limit == 0 as "no limit" 762 if (limit) { 763 psString limitString = psDBGenerateLimitSQL(limit); 764 psStringAppend(&query, " %s", limitString); 765 psFree(limitString); 766 } 767 768 if (!p_psDBRunQueryF(config->dbh, query, whereString, whereString)) { 769 psError(PS_ERR_UNKNOWN, false, "database error"); 770 psFree(whereString); 761 771 psFree(query); 762 772 return false; … … 782 792 } 783 793 794 if (limit) { 795 if (psArrayLength(output) >= limit) { 796 // we've found enough (not that limit was applied to the query so '> limit' won't happen) 797 // negative simple so the default is true 798 if (!ippdbPrintMetadatas(stdout, output, "magicMe", !simple)) { 799 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 800 psFree(output); 801 return false; 802 } 803 psFree(output); 804 return true; 805 } 806 } 807 784 808 // look for tree nodes that need to be processed 809 // XXX: This gets all nodes from all magicRuns that are in 'new'state 810 // That doens't seem particularly efficient 785 811 query = pxDataGet("magictool_toprocess_tree.sql"); 786 812 if (!query) { … … 789 815 } 790 816 791 if (whereClause) { 792 psString new = NULL; 793 psStringAppend(&new, "\n AND %s", whereClause); 794 psFree(whereClause); 795 whereClause = new; 796 } 797 if (!p_psDBRunQueryF(config->dbh, query, whereClause ? whereClause : "")) { 798 psError(PS_ERR_UNKNOWN, false, "database error"); 799 psFree(whereClause); 817 818 if (!p_psDBRunQueryF(config->dbh, query, whereString ? whereString : "")) { 819 psError(PS_ERR_UNKNOWN, false, "database error"); 820 psFree(whereString); 800 821 psFree(query); 801 822 return false; 802 823 } 803 psFree(where Clause);824 psFree(whereString); 804 825 psFree(query); 805 826 … … 828 849 while (index < psArrayLength(magicTree)) { 829 850 bool status; 851 if (limit && (psArrayLength(output) >= limit)) { 852 break; 853 } 830 854 psS64 current_magic_id = psMetadataLookupS64(&status, magicTree->data[index], "magic_id"); 831 855 if (!status) { … … 879 903 880 904 } 905 psFree(magicTree); 881 906 882 907 if (psArrayLength(output)) { 908 if (limit && (limit < psArrayLength(output))) { 909 // truncate the array 910 long arrayLength = psArrayLength(output); 911 for (long i = arrayLength - 1; i >= limit; i--) { 912 psArrayRemoveIndex(output, i); 913 } 914 } 883 915 // negative simple so the default is true 884 916 if (!ippdbPrintMetadatas(stdout, output, "magicMe", !simple)) { … … 889 921 } 890 922 891 psFree(magicTree);892 923 psFree(output); 893 924
Note:
See TracChangeset
for help on using the changeset viewer.
