You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by th...@apache.org on 2021/10/06 15:52:29 UTC
[jackrabbit-oak] 01/01: OAK-9595 XPath queries don't support bind
variables
This is an automated email from the ASF dual-hosted git repository.
thomasm pushed a commit to branch OAK-9595
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit 0cfe36347980b90977bd59bc70aefc861cc1ae35
Author: thomasm <th...@apache.org>
AuthorDate: Wed Oct 6 17:52:18 2021 +0200
OAK-9595 XPath queries don't support bind variables
---
.../org/apache/jackrabbit/oak/query/xpath/Expression.java | 4 ++++
.../jackrabbit/oak/query/xpath/XPathToSQL2Converter.java | 2 ++
.../resources/org/apache/jackrabbit/oak/query/xpath.txt | 14 +++++++++++---
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Expression.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Expression.java
index edc3e96..498c386 100644
--- a/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Expression.java
+++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Expression.java
@@ -180,6 +180,10 @@ abstract class Expression {
static Literal newString(String s) {
return new Literal(SQL2Parser.escapeStringLiteral(s), s);
}
+
+ static Literal newBindVariable(String s) {
+ return new Literal("@" + s, s);
+ }
@Override
public String toString() {
diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
index a88d7b6..711c7fd 100644
--- a/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
+++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
@@ -624,6 +624,8 @@ public class XPathToSQL2Converter {
read(")");
}
return Expression.Literal.newBoolean(false);
+ } else if (readIf("$")) {
+ return Expression.Literal.newBindVariable(readIdentifier());
} else if (currentTokenType == VALUE_NUMBER) {
Expression.Literal l = Expression.Literal.newNumber(currentToken);
read();
diff --git a/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt b/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
index 213173a..0098931 100644
--- a/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
+++ b/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
@@ -26,6 +26,14 @@
#
+xpath2sql /jcr:root/content//element(*, nt:base)[@jcr:lastModified >= $lastModified] order by @jcr:lastModified, @jcr:path
+select [jcr:path], [jcr:score], *
+ from [nt:base] as a
+ where [jcr:lastModified] >= @lastModified
+ and isdescendantnode(a, '/content')
+ order by [jcr:lastModified], [jcr:path]
+ /* xpath ... */
+
xpath2sql /jcr:root//element(*, nt:base)[jcr:contains(., 'hello')]/rep:excerpt()
select [jcr:path], [jcr:score], [rep:excerpt]
from [nt:base] as a
@@ -1755,13 +1763,13 @@ xpath2sql //element(*, my:type)[@my:value = +'x']
invalid: Query: //element(*, my:type)[@my:value = +'x'(*)]
xpath2sql //element(*, my:type)[@my:value = ['x']
-invalid: Query: //element(*, my:type)[@my:value = [(*)'x']; expected: @, true, false, -, +, *, ., @, (
+invalid: Query: //element(*, my:type)[@my:value = [(*)'x']; expected: @, true, false, $, -, +, *, ., @, (
xpath2sql //element(*, my:type)[jcr:strike(@title,'%Java%')]
invalid: Query: //element(*, my:type)[jcr:strike(@(*)title,'%Java%')]; expected: jcr:like | jcr:contains | jcr:score | xs:dateTime | fn:lower-case | fn:upper-case | fn:name | rep:similar | rep:spellcheck | rep:suggest
xpath2sql //element(*, my:type)[
-invalid: Query: //element(*, my:type)(*)[; expected: fn:not, not, (, @, true, false, -, +, *, ., @, (
+invalid: Query: //element(*, my:type)(*)[; expected: fn:not, not, (, @, true, false, $, -, +, *, ., @, (
xpath2sql //element(*, my:type)[@my:value >= %]
-invalid: Query: //element(*, my:type)[@my:value >= %(*)]; expected: @, true, false, -, +, *, ., @, (
+invalid: Query: //element(*, my:type)[@my:value >= %(*)]; expected: @, true, false, $, -, +, *, ., @, (