jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r785580 - in /jackrabbit/trunk/jackrabbit-spi-commons/src: main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java test/resources/org/apache/jackrabbit/spi/commons/query/sql2/test.sql2.txt
Date Wed, 17 Jun 2009 13:03:25 GMT
Author: thomasm
Date: Wed Jun 17 13:03:25 2009
New Revision: 785580

URL: http://svn.apache.org/viewvc?rev=785580&view=rev
Log:
JCR-2155 SQL2 parser: identifiers should be case sensitive

Modified:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/resources/org/apache/jackrabbit/spi/commons/query/sql2/test.sql2.txt

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java?rev=785580&r1=785579&r2=785580&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java
Wed Jun 17 13:03:25 2009
@@ -120,6 +120,9 @@
             read("BY");
             orderings = parseOrder();
         }
+        if (currentToken.length() > 0) {
+            throw getSyntaxError("<end>");
+        }
         return factory.createQuery(source, constraint, orderings, columnArray);
     }
 
@@ -192,7 +195,7 @@
         String name = readName();
         JoinCondition c;
         if (identifier && readIf("(")) {
-            if ("ISSAMENODE".equals(name)) {
+            if ("ISSAMENODE".equalsIgnoreCase(name)) {
                 String selector1 = readName();
                 read(",");
                 String selector2 = readName();
@@ -202,11 +205,11 @@
                     // TODO verify "." is correct
                     c = factory.sameNodeJoinCondition(selector1, selector2, ".");
                 }
-            } else if ("ISCHILDNODE".equals(name)) {
+            } else if ("ISCHILDNODE".equalsIgnoreCase(name)) {
                 String childSelector = readName();
                 read(",");
                 c = factory.childNodeJoinCondition(childSelector, readName());
-            } else if ("ISDESCENDANTNODE".equals(name)) {
+            } else if ("ISDESCENDANTNODE".equalsIgnoreCase(name)) {
                 String descendantSelector = readName();
                 read(",");
                 c = factory.descendantNodeJoinCondition(descendantSelector, readName());
@@ -322,7 +325,7 @@
 
     private Constraint parseConditionFuntionIf(String functionName) throws RepositoryException
{
         Constraint c;
-        if ("CONTAINS".equals(functionName)) {
+        if ("CONTAINS".equalsIgnoreCase(functionName)) {
             String name = readName();
             if (readIf(".")) {
                 if (readIf("*")) {
@@ -338,21 +341,21 @@
                 read(",");
                 c = factory.fullTextSearch(getOnlySelectorName(), name, readString());
             }
-        } else if ("ISSAMENODE".equals(functionName)) {
+        } else if ("ISSAMENODE".equalsIgnoreCase(functionName)) {
             String name = readName();
             if (readIf(",")) {
                 c = factory.sameNode(name, readPath());
             } else {
                 c = factory.sameNode(getOnlySelectorName(), name);
             }
-        } else if ("ISCHILDNODE".equals(functionName)) {
+        } else if ("ISCHILDNODE".equalsIgnoreCase(functionName)) {
             String name = readName();
             if (readIf(",")) {
                 c = factory.childNode(name, readPath());
             } else {
                 c = factory.childNode(getOnlySelectorName(), name);
             }
-        } else if ("ISDESCENDANTNODE".equals(functionName)) {
+        } else if ("ISDESCENDANTNODE".equalsIgnoreCase(functionName)) {
             String name = readName();
             if (readIf(",")) {
                 c = factory.descendantNode(name, readPath());
@@ -382,29 +385,29 @@
 
     private DynamicOperand parseExpressionFunction(String functionName) throws RepositoryException
{
         DynamicOperand op;
-        if ("LENGTH".equals(functionName)) {
+        if ("LENGTH".equalsIgnoreCase(functionName)) {
             op = factory.length(parsePropertyValue(readName()));
-        } else if ("NAME".equals(functionName)) {
+        } else if ("NAME".equalsIgnoreCase(functionName)) {
             if (isToken(")")) {
                 op = factory.nodeName(getOnlySelectorName());
             } else {
                 op = factory.nodeName(readName());
             }
-        } else if ("LOCALNAME".equals(functionName)) {
+        } else if ("LOCALNAME".equalsIgnoreCase(functionName)) {
             if (isToken(")")) {
                 op = factory.nodeLocalName(getOnlySelectorName());
             } else {
                 op = factory.nodeLocalName(readName());
             }
-        } else if ("SCORE".equals(functionName)) {
+        } else if ("SCORE".equalsIgnoreCase(functionName)) {
             if (isToken(")")) {
                 op = factory.fullTextSearchScore(getOnlySelectorName());
             } else {
                 op = factory.fullTextSearchScore(readName());
             }
-        } else if ("LOWER".equals(functionName)) {
+        } else if ("LOWER".equalsIgnoreCase(functionName)) {
             op = factory.lowerCase(parseDynamicOperand());
-        } else if ("UPPER".equals(functionName)) {
+        } else if ("UPPER".equalsIgnoreCase(functionName)) {
             op = factory.upperCase(parseDynamicOperand());
         } else {
             throw getSyntaxError("LENGTH, NAME, LOCALNAME, SCORE, LOWER, UPPER, or CAST");
@@ -454,6 +457,9 @@
         } else if (currentTokenType == PARAMETER) {
             read();
             String name = readName();
+            if (readIf(":")) {
+                name = name + ":" + readName();
+            }
             BindVariableValue var = bindVariables.get(name);
             if (var == null) {
                 var = factory.bindVariable(name);
@@ -483,7 +489,7 @@
             throw getSyntaxError("static operand");
         }
     }
-    
+
     private Value parseCastAs(Value value) throws RepositoryException {
         if (readIf("STRING")) {
             return valueFactory.createValue(value.getString());
@@ -610,7 +616,7 @@
     }
 
     private boolean isToken(String token) {
-        boolean result = token.equals(currentToken) && !currentTokenQuoted;
+        boolean result = token.equalsIgnoreCase(currentToken) && !currentTokenQuoted;
         if (result) {
             return true;
         }
@@ -619,7 +625,7 @@
     }
 
     private void read(String expected) throws RepositoryException {
-        if (!expected.equals(currentToken) || currentTokenQuoted) {
+        if (!expected.equalsIgnoreCase(currentToken) || currentTokenQuoted) {
             throw getSyntaxError(expected);
         }
         read();
@@ -664,7 +670,6 @@
         int[] types = new int[len];
         len--;
         query.getChars(0, len, command, 0);
-        boolean changed = false;
         command[len] = ' ';
         int startLoop = 0;
         for (int i = 0; i < len; i++) {
@@ -720,8 +725,6 @@
                 break;
             default:
                 if (c >= 'a' && c <= 'z') {
-                    command[i] = (char) (c - ('a' - 'A'));
-                    changed = true;
                     type = CHAR_NAME;
                 } else if (c >= 'A' && c <= 'Z') {
                     type = CHAR_NAME;
@@ -730,11 +733,6 @@
                 } else {
                     if (Character.isJavaIdentifierPart(c)) {
                         type = CHAR_NAME;
-                        char u = Character.toUpperCase(c);
-                        if (u != c) {
-                            command[i] = u;
-                            changed = true;
-                        }
                     }
                 }
             }
@@ -743,9 +741,6 @@
         statementChars = command;
         types[len] = CHAR_END;
         characterTypes = types;
-        if (changed) {
-            statement = new String(command);
-        }
         parseIndex = 0;
     }
 
@@ -825,12 +820,12 @@
                         readDecimal(start, i);
                         break;
                     }
-                    if (c == 'E') {
+                    if (c == 'E' || c == 'e') {
                         readDecimal(start, i);
                         break;
                     }
                     checkLiterals(false);
-                    currentValue = valueFactory.createValue((long) number);
+                    currentValue = valueFactory.createValue(number);
                     currentTokenType = VALUE;
                     currentToken = "0";
                     parseIndex = i;
@@ -868,7 +863,7 @@
             throw getSyntaxError();
         }
     }
-    
+
     private void readString(int i, char end) throws RepositoryException {
         char[] chars = statementChars;
         String result = null;
@@ -911,7 +906,7 @@
             }
             i++;
         }
-        if (chars[i] == 'E') {
+        if (chars[i] == 'E' || chars[i] == 'e') {
             i++;
             if (chars[i] == '+' || chars[i] == '-') {
                 i++;
@@ -932,7 +927,7 @@
             throw new InvalidQueryException("Data conversion error converting " + sub + "
to BigDecimal: " + e);
         }
         checkLiterals(false);
-        
+
         currentValue = valueFactory.createValue(bd);
         currentTokenType = VALUE;
     }
@@ -954,7 +949,7 @@
 
     private InvalidQueryException getSyntaxError(String expected) {
         int index = Math.min(parseIndex, statement.length() - 1);
-        String query = statement.substring(0, index) + ">*<" + statement.substring(index).trim();
+        String query = statement.substring(0, index) + "(*)" + statement.substring(index).trim();
         if (expected != null) {
             query += "; expected: " + expected;
         }
@@ -970,11 +965,11 @@
         private String propertyName;
         private String columnName;
     }
-    
+
     /**
      * Get the selector name if only one selector exists in the query.
      * If more than one selector exists, an exception is thrown.
-     * 
+     *
      * @return the selector name
      */
     private String getOnlySelectorName() throws RepositoryException {

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/test/resources/org/apache/jackrabbit/spi/commons/query/sql2/test.sql2.txt
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/resources/org/apache/jackrabbit/spi/commons/query/sql2/test.sql2.txt?rev=785580&r1=785579&r2=785580&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/resources/org/apache/jackrabbit/spi/commons/query/sql2/test.sql2.txt
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/resources/org/apache/jackrabbit/spi/commons/query/sql2/test.sql2.txt
Wed Jun 17 13:03:25 2009
@@ -17,8 +17,12 @@
 
 # See also jcr-spec.pdf
 
+select * from test where name=$nt:name
+
 # 6.7.1 Query (p 99)
 select * from test
+SELECT * FROM TEST
+SeLeCt * FrOm test
 select * from test where id=1
 select * from test where id=1 order by id
 select * from test order by id
@@ -171,15 +175,11 @@
 select * from test where name=$x and id=$y
 select * from test where name=$x14
 select * from test where name=$_
-select * from test where name=$äöü
-select * from test where name=$äöü
 
 # 6.7.36 Prefix (p 124)
 select * from test where name=$nt:name
 select * from test where name=$_:name
 select * from test where name=$_1:name
-select * from test where name=$_-.0:name
-select * from test where name=$x..:name
 
 # 6.7.37 Ordering (p 125)
 # 6.7.38 Order (p 126)



Mime
View raw message