jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1419391 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java test/resources/org/apache/jackrabbit/oak/query/sql2.txt
Date Mon, 10 Dec 2012 12:53:11 GMT
Author: thomasm
Date: Mon Dec 10 12:53:10 2012
New Revision: 1419391

URL: http://svn.apache.org/viewvc?rev=1419391&view=rev
Log:
OAK-499 SQL-2 query parser doesn't detect some illegal statements

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
    jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2.txt

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java?rev=1419391&r1=1419390&r2=1419391&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
Mon Dec 10 12:53:10 2012
@@ -525,6 +525,23 @@ public class SQL2Parser {
     private StaticOperandImpl parseStaticOperand() throws ParseException {
         if (currentTokenType == PLUS) {
             read();
+            if (currentTokenType != VALUE) {
+                throw getSyntaxError("number");
+            }
+            int valueType = currentValue.getType().tag();
+            switch (valueType) {
+            case PropertyType.LONG:
+                currentValue = PropertyValues.newLong(currentValue.getValue(Type.LONG));
+                break;
+            case PropertyType.DOUBLE:
+                currentValue = PropertyValues.newDouble(currentValue.getValue(Type.DOUBLE));
+                break;
+            case PropertyType.DECIMAL:
+                currentValue = PropertyValues.newDecimal(currentValue.getValue(Type.DECIMAL).negate());
+                break;
+            default:
+                throw getSyntaxError("Illegal operation: + " + currentValue);
+            }
         } else if (currentTokenType == MINUS) {
             read();
             if (currentTokenType != VALUE) {
@@ -923,7 +940,10 @@ public class SQL2Parser {
             if (types[i] == CHAR_SPECIAL_2) {
                 i++;
             }
-            // fall through
+            currentToken = statement.substring(start, i);
+            currentTokenType = KEYWORD;
+            parseIndex = i;
+            return;
         case CHAR_SPECIAL_1:
             currentToken = statement.substring(start, i);
             switch (c) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2.txt
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2.txt?rev=1419391&r1=1419390&r2=1419391&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2.txt
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2.txt
Mon Dec 10 12:53:10 2012
@@ -274,3 +274,10 @@ select * from [nt:base] where upper(name
 select * from [nt:base] where upper(name) like '10\%'
 /testRoot/test4
 
+# errors
+
+select * from [nt:base] where name =+ 'Hello'
+java.text.ParseException: Query: select * from [nt:base] where name =+ 'Hello(*)'; expected:
Illegal operation: + Hello
+
+select * from [nt:base] where name => 'Hello'
+java.text.ParseException: Query: select * from [nt:base] where name =>(*)'Hello'; expected:
(, ., =, <>, <, >, <=, >=, LIKE, IS, NOT



Mime
View raw message