db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1431259 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Date Thu, 10 Jan 2013 10:28:34 GMT
Author: kahatlen
Date: Thu Jan 10 10:28:33 2013
New Revision: 1431259

URL: http://svn.apache.org/viewvc?rev=1431259&view=rev
Log:
DERBY-6030: Length of escape string in LIKE ... ESCAPE not properly checked with territory
based collation

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java?rev=1431259&r1=1431258&r2=1431259&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java
Thu Jan 10 10:28:33 2013
@@ -153,7 +153,8 @@ final class WorkHorseForCollatorDatatype
 
 		CollationElementsInterface escapeCharacter = (CollationElementsInterface) escape;
 
-		if (!escapeCharacter.hasSingleCollationElement())
+        if (escape.getLength() != 1 ||
+                !escapeCharacter.hasSingleCollationElement())
 		{
 			throw StandardException.newException(SQLState.LANG_INVALID_ESCAPE_CHARACTER,
 					escapeCharacter.toString());

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java?rev=1431259&r1=1431258&r2=1431259&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Thu Jan 10 10:28:33 2013
@@ -81,6 +81,7 @@ public class CollationTest extends BaseJ
     /** Test cases to run with Norwegian case-sensitive collation. */
     private final static String[] NORWEGIAN_CASE_SENSITIVE = {
         "testNorwayCollation",
+        "testLikeEscapeClauseLengthRestriction",
     };
 
     /** Test cases to run with Polish case-sensitive collation. */
@@ -98,6 +99,9 @@ public class CollationTest extends BaseJ
         "testSwedishCaseInsensitiveCollation",
     };
 
+    /** SQL state that signals invalid escape sequence in LIKE expressions. */
+    private final static String INVALID_ESCAPE = "22019";
+
   /**
    * Test order by with default collation
    * 
@@ -2189,4 +2193,49 @@ public void testMissingCollatorSupport()
         return new HarmonySerialClob( contents );
     }
 
+    /**
+     * Regression test case for DERBY-6030. The escape sequence in a LIKE
+     * expression should consist of a single character and a single collation
+     * element. Before DERBY-6030, with non-literal escape sequences, Derby
+     * would only check that the sequence consisted of a single collation
+     * element, and might incorrectly accept escape sequences with more than
+     * one character.
+     */
+    public void testLikeEscapeClauseLengthRestriction() throws SQLException {
+        setAutoCommit(false);
+        Statement s = createStatement();
+        s.execute("create table d6030" +
+                  "(x varchar(10), y varchar(10), z varchar(10))");
+        s.execute("insert into d6030 values ('a', 'b', 'c')");
+
+        PreparedStatement select = prepareStatement(
+            "select * from d6030 where x like y escape z");
+
+        PreparedStatement update = prepareStatement("update d6030 set z = ?");
+
+        // Escape clause 'c' is OK.
+        JDBC.assertEmpty(select.executeQuery());
+
+        // Sharp-s is NOT OK, as it has two collation elements.
+        update.setString(1, "\u00df");
+        assertUpdateCount(update, 1);
+        assertStatementError(INVALID_ESCAPE, select);
+
+        // 'aa' is NOT OK, as it has two characters. This used to succeed with
+        // Norwegian collation, which treats 'aa' as a single collation
+        // element. But it should fail since it's two characters.
+        update.setString(1, "aa");
+        assertUpdateCount(update, 1);
+        assertStatementError(INVALID_ESCAPE, select);
+
+        // Also test the same queries with literals in the escape clause.
+        // Those queries follow a different code path, and they produced the
+        // expected results even before the fix.
+        JDBC.assertEmpty(
+            s.executeQuery("select * from d6030 where x like y escape 'c'"));
+        assertStatementError(INVALID_ESCAPE, s,
+                "select * from d6030 where x like y escape '\u00df'");
+        assertStatementError(INVALID_ESCAPE, s,
+                "select * from d6030 where x like y escape 'aa'");
+    }
 }



Mime
View raw message