db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrnap <my...@Golux.Com>
Subject [PATCH] JIRA-DERBY-44 - Like ? escape ?
Date Fri, 05 Nov 2004 03:08:23 GMT
This error came out of sqlgrammar.jj, and after taking the section 
throwing the error out, all seemed to work fine except for a problem in 
optimization when the string passed on in the escape happened to be 
empty. So that's addressed in the Like.java.
As the section in sqlgrammar.jj was the only location where the error 
22500,  LANG_LIKE_AND_ESCAPE_PARAM was used, I removed it from relevant 
files.

Index: java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
===================================================================
--- java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj    
(revision 56257)
+++ java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj    
(working copy)
@@ -4710,19 +4710,6 @@
                 <LEFT_BRACE> <ESCAPE> escapeValue = 
additiveExpression(null, 0, inSelectClause) <RIGHT_BRACE>
             ]
     {
-        //
-        // Error on the too hard to handle corner case of LIKE ? ESCAPE ?.
-        // The problem is at execution when we process the first ? we
-        // call Like.lssThanString/greaterThanString() with escape == null.
-        // There is no way to jam the escape parameter up for use in
-        // ExecAssociatedLikeParameter
-        //
-
-        if (escapeValue != null && escapeValue instanceof ParameterNode
-            && likePattern instanceof ParameterNode)
-        {
-            throw 
StandardException.newException(SQLState.LANG_LIKE_AND_ESCAPE_PARAM);
-        }
         tree = (ValueNode) nodeFactory.getNode(
                                 C_NodeTypes.LIKE_OPERATOR_NODE,
                                 leftOperand,
Index: java/engine/org/apache/derby/iapi/types/Like.java
===================================================================
--- java/engine/org/apache/derby/iapi/types/Like.java    (revision 56257)
+++ java/engine/org/apache/derby/iapi/types/Like.java    (working copy)
@@ -721,7 +721,7 @@
         // what is there, while stripping escapes
         //
 
-        if (escape != null)
+        if ((escape != null) && (escape.length() != 0))
         {
             char escChar = escape.charAt(0);
             if (pattern.indexOf(escChar) != -1)
@@ -943,7 +943,7 @@
             return null;
         }
 
-        if (escape != null)
+        if ((escape != null) && (escape.length() !=0))
         {
             escChar = escape.charAt(0);
         }
Index: java/engine/org/apache/derby/iapi/reference/SQLState.java
===================================================================
--- java/engine/org/apache/derby/iapi/reference/SQLState.java    
(revision 56257)
+++ java/engine/org/apache/derby/iapi/reference/SQLState.java    
(working copy)
@@ -658,7 +658,6 @@
     String LANG_INVALID_ESCAPE_CHARACTER                               
= "22019";
     String LANG_INVALID_ESCAPE_SEQUENCE                                
= "22025";
     String LANG_INVALID_TRIM_SET                                       
= "22027";
-    String LANG_LIKE_AND_ESCAPE_PARAM                                  
= "22500";
     String LANG_ESCAPE_IS_NULL                                         
= "22501";
     String LANG_NULL_INTO_NON_NULL                                     
= "23502";
     String LANG_DUPLICATE_KEY_CONSTRAINT                               
= "23505";
Index: java/engine/org/apache/derby/loc/messages_en.properties
===================================================================
--- java/engine/org/apache/derby/loc/messages_en.properties    (revision 
56257)
+++ java/engine/org/apache/derby/loc/messages_en.properties    (working 
copy)
@@ -370,7 +370,6 @@
 22019=Invalid escape sequence, ''{0}''. The escape string must be 
exactly one character. It can not be a null or more than one character.
 22025=Escape character must be followed by escape character, '_', or 
'%'. It cannot be followed by any other character or be at the end of 
the pattern.
 22027=The built-in TRIM() function only supports a single trim 
character.  The LTRIM() and RTRIM() built-in functions support multiple 
trim characters.
-22500=Cannot use ? parameters for both the LIKE pattern and the ESCAPE 
clause.
 22501=An ESCAPE clause of NULL returns undefined results and is not 
allowed.
 23502=Column ''{0}''  cannot accept a NULL value.
 23505=The statement was aborted because it would have caused a 
duplicate key value in a unique or primary key constraint or unique 
index identified by ''{0}'' defined on ''{1}''.




Mime
View raw message