Revision 6734
Added by ben leinfelder about 13 years ago
src/edu/ucsb/nceas/metacat/QuerySpecification.java | ||
---|---|---|
859 | 859 |
* @param useXMLIndex a boolean flag indicating whether to search using |
860 | 860 |
* xml_index |
861 | 861 |
*/ |
862 |
public String printExtendedSQL(String doclist, boolean useXMLIndex, List<Object> allValues) |
|
862 |
public String printExtendedSQL(String doclist, boolean useXMLIndex, List<Object> allValues, List<Object> docListValues)
|
|
863 | 863 |
{ |
864 | 864 |
|
865 | 865 |
// keep track of the values we add as prepared statement question marks (?) |
... | ... | |
868 | 868 |
if (useXMLIndex && !containsPredicates) { |
869 | 869 |
// keep track of the values we add as prepared statement question marks (?) |
870 | 870 |
List<Object> parameterValues = new ArrayList<Object>(); |
871 |
String query = printExtendedSQL(doclist, parameterValues); |
|
871 |
String query = printExtendedSQL(doclist, parameterValues, docListValues);
|
|
872 | 872 |
// add parameter values to our running list |
873 | 873 |
allValues.addAll(parameterValues); |
874 | 874 |
return query; |
... | ... | |
880 | 880 |
// keep track of the values we add as prepared statement question marks (?) |
881 | 881 |
List<Object> parameterValues = new ArrayList<Object>(); |
882 | 882 |
// first part comes from fields without predicates |
883 |
String queryFromWithoutPrecidates = printExtendedSQL(doclist, parameterValues); |
|
883 |
String queryFromWithoutPrecidates = printExtendedSQL(doclist, parameterValues, docListValues);
|
|
884 | 884 |
// add parameter values to our running list |
885 | 885 |
allValues.addAll(parameterValues); |
886 | 886 |
if (queryFromWithoutPrecidates != null) { |
... | ... | |
901 | 901 |
self.append(" UNION "); |
902 | 902 |
} |
903 | 903 |
String path = (String) returnFieldListWithPredicates.elementAt(i); |
904 |
path = path.replaceAll("'", "''"); |
|
904 |
//path = path.replaceAll("'", "''");
|
|
905 | 905 |
// TODO: can we use prepared statements for this? |
906 | 906 |
allValues.add(path); |
907 | 907 |
self.append("select xml_nodes.docid, "); |
... | ... | |
921 | 921 |
|
922 | 922 |
self.append(" AND xml_nodes.docid in ("); |
923 | 923 |
self.append(doclist); |
924 |
allValues.addAll(docListValues); |
|
925 |
|
|
924 | 926 |
if (returnFieldIsAttribute(path)) |
925 | 927 |
{ |
926 | 928 |
self.append(")"); |
... | ... | |
976 | 978 |
* @param unaccessableNodePair the node pairs (start id and end id) |
977 | 979 |
* which this user should not access |
978 | 980 |
*/ |
979 |
private String printExtendedSQL(String doclist, List<Object> values) { |
|
981 |
private String printExtendedSQL(String doclist, List<Object> values, List<Object> docListValues) {
|
|
980 | 982 |
|
981 | 983 |
// keep track of the values we add as prepared statement question marks (?) |
982 | 984 |
//List<Object> values = new ArrayList<Object>(); |
... | ... | |
1046 | 1048 |
} |
1047 | 1049 |
self.append(") AND docid in ("); |
1048 | 1050 |
self.append(doclist); |
1051 |
values.addAll(docListValues); |
|
1049 | 1052 |
self.append(")"); |
1050 | 1053 |
|
1051 | 1054 |
} else { |
... | ... | |
1105 | 1108 |
|
1106 | 1109 |
self.append(") AND xml_nodes.docid in ("); |
1107 | 1110 |
self.append(doclist); |
1111 |
values.addAll(docListValues); |
|
1108 | 1112 |
self.append(")"); |
1109 | 1113 |
|
1110 | 1114 |
} |
src/edu/ucsb/nceas/metacat/DBQuery.java | ||
---|---|---|
1266 | 1266 |
|
1267 | 1267 |
|
1268 | 1268 |
String extendedQuery = |
1269 |
qspec.printExtendedSQL(doclist.toString(), useXMLIndex, parameterValues); |
|
1270 |
// add them after, since the doclist clause is at the end of the generated queries
|
|
1271 |
parameterValues.addAll(doclistValues); |
|
1269 |
qspec.printExtendedSQL(doclist.toString(), useXMLIndex, parameterValues, doclistValues);
|
|
1270 |
// DO not add doclist values -- they are included in the query
|
|
1271 |
//parameterValues.addAll(doclistValues);
|
|
1272 | 1272 |
logMetacat.info("DBQuery.addReturnfield - Extended query: " + extendedQuery); |
1273 | 1273 |
|
1274 | 1274 |
if(extendedQuery != null){ |
src/edu/ucsb/nceas/metacat/QueryTerm.java | ||
---|---|---|
589 | 589 |
if (sQuote == -1 && dQuote == -1) |
590 | 590 |
{ |
591 | 591 |
log.warn("predicate2SQL(): "); |
592 |
log.warn(" Invalid or unsupported predicate: " + predicate); |
|
592 |
log.warn(" 1 Invalid or unsupported predicate: " + predicate);
|
|
593 | 593 |
return ""; |
594 | 594 |
} |
595 | 595 |
|
... | ... | |
598 | 598 |
literal.indexOf('"', dQuote + 1) != literal.length() - 1)) |
599 | 599 |
{ |
600 | 600 |
log.warn("predicate2SQL(): "); |
601 |
log.warn(" Invalid or unsupported predicate: " + predicate); |
|
601 |
log.warn(" 2 Invalid or unsupported predicate: " + predicate);
|
|
602 | 602 |
return ""; |
603 | 603 |
} |
604 | 604 |
|
... | ... | |
606 | 606 |
literal.indexOf('\'', sQuote + 1) != literal.length() - 1) |
607 | 607 |
{ |
608 | 608 |
log.warn("predicate2SQL(): "); |
609 |
log.warn(" Invalid or unsupported predicate: " + predicate); |
|
609 |
log.warn(" 3 Invalid or unsupported predicate: " + predicate);
|
|
610 | 610 |
return ""; |
611 | 611 |
} |
612 | 612 |
} |
Also available in: Unified diff
handle queries with predicates correctly.
when docids are used in the return field look up, we need to make sure they are included in the values in the correct order for their corresponding parameter place holders (?)