db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r536661 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/types/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Wed, 09 May 2007 21:27:19 GMT
Author: mamta
Date: Wed May  9 14:27:18 2007
New Revision: 536661

URL: http://svn.apache.org/viewvc?view=rev&rev=536661
Log:
DERBY-2335 This commit adds some basics tests and fixes a bug that I came across while writing
the tests. The problem is that
SQLChar has a method called stringCompare(SQLChar, SQLChar). This method compares the 2 passed
parameters. When I 
implemented this method for CollatorSQLxxx classes, I was making the assumption that first
parameter SQLChar is same
as the SQLChar object on which the method is getting called and hence I was ignoring the 1st
parameter and comparing
the object on which stringCompare is called with the 2nd paramter to stringCompare method.
But that assumption is not 
correct. I discovered that when I wrote a test like following
select id, name from customer where 'a'='b' 
The where clause for territory based collated db always returned true because of the bug/wrong
assumption.
This is because stringCompare was getting called with first parameter as SQLChar 'b' and 2nd
parameter as SQLChar 'a' and 
stringCompare was getting called off of the object for 'a' and hence, at runtime the comparison
was happening between 2 'a's 
rather than 'a' and 'b'. In order to fix this, I am having stringCompare on ColatorSQLxxx
methods use both the passed SQLChars 
to do the comparison rather than ignorning the first SQLChar(just like what we do for existing
SQLChar classes). This fixes the problem.

In addition, I have enabled the testing for territory based collated db in CollationTest added
by Kathey (Thanks for 
starting this test off, Kathey). There are 3 databases with territory based collation, for
Polish, Norway and English.

And lastly, I have added 2 simple character constant tests for each of the 4 databases (3
territory based collated dbs and 
one default collation db). One of these 2 simple tests will give different results based on
the collation used.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java
    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/CollatorSQLChar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java?view=diff&rev=536661&r1=536660&r2=536661
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java Wed May
 9 14:27:18 2007
@@ -141,11 +141,11 @@
 		}
 	}
 	
-	/** @see SQLChar.stringCompare(SQLChar, SQLChar) */
+	/** @see SQLChar#stringCompare(SQLChar, SQLChar) */
 	 protected int stringCompare(SQLChar char1, SQLChar char2)
 	 throws StandardException
 	 {
-		 return holderForCollationSensitiveInfo.stringCompare(char2);
+		 return holderForCollationSensitiveInfo.stringCompare(char1, char2);
 	 }
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java?view=diff&rev=536661&r1=536660&r2=536661
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java Wed May
 9 14:27:18 2007
@@ -141,11 +141,11 @@
 		}
 	}
 	
-	/** @see SQLChar.stringCompare(SQLChar, SQLChar) */
+	/** @see SQLChar#stringCompare(SQLChar, SQLChar) */
 	 protected int stringCompare(SQLChar char1, SQLChar char2)
 	 throws StandardException
 	 {
-		 return holderForCollationSensitiveInfo.stringCompare(char2);
+		 return holderForCollationSensitiveInfo.stringCompare(char1, char2);
 	 }
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java?view=diff&rev=536661&r1=536660&r2=536661
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java
Wed May  9 14:27:18 2007
@@ -141,11 +141,11 @@
 		}
 	}
 	
-	/** @see SQLChar.stringCompare(SQLChar, SQLChar) */
+	/** @see SQLChar#stringCompare(SQLChar, SQLChar) */
 	 protected int stringCompare(SQLChar char1, SQLChar char2)
 	 throws StandardException
 	 {
-		 return holderForCollationSensitiveInfo.stringCompare(char2);
+		 return holderForCollationSensitiveInfo.stringCompare(char1, char2);
 	 }
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java?view=diff&rev=536661&r1=536660&r2=536661
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java Wed
May  9 14:27:18 2007
@@ -141,11 +141,11 @@
 		}
 	}
 	
-	/** @see SQLChar.stringCompare(SQLChar, SQLChar) */
+	/** @see SQLChar#stringCompare(SQLChar, SQLChar) */
 	 protected int stringCompare(SQLChar char1, SQLChar char2)
 	 throws StandardException
 	 {
-		 return holderForCollationSensitiveInfo.stringCompare(char2);
+		 return holderForCollationSensitiveInfo.stringCompare(char1, char2);
 	 }
 
 	/**

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?view=diff&rev=536661&r1=536660&r2=536661
==============================================================================
--- 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
Wed May  9 14:27:18 2007
@@ -83,10 +83,10 @@
 	}
 	
 	/** @see SQLChar.stringCompare(SQLChar, SQLChar) */
-	protected int stringCompare(SQLChar str2)
+	protected int stringCompare(SQLChar str1, SQLChar str2)
 	throws StandardException
 	{
-		CollationKey ckey1 = stringData.getCollationKey();
+		CollationKey ckey1 = str1.getCollationKey();
 		CollationKey ckey2 = str2.getCollationKey();
 		
 		/*

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?view=diff&rev=536661&r1=536660&r2=536661
==============================================================================
--- 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
Wed May  9 14:27:18 2007
@@ -63,8 +63,17 @@
       DataSource ds = JDBCDataSource.getDataSourceLogical("defaultdb");
       JDBCDataSource.setBeanProperty(ds, "connectionAttributes", 
                   "create=true");
-      checkLangBasedQuery(ds, new String[][] {{"4","Acorn"},{"0","Smith"},{"1","Zebra"},
-              {"6","aacorn"}, {"2","\u0104corn"},{"5","\u015Amith"},{"3","\u017Bebra"}});
     
+      setUpTable(ds);
+      checkLangBasedQuery(ds, "SELECT ID, NAME FROM CUSTOMER ORDER BY NAME",
+      		new String[][] {{"4","Acorn"},{"0","Smith"},{"1","Zebra"},
+      		{"6","aacorn"}, {"2","\u0104corn"},{"5","\u015Amith"},{"3","\u017Bebra"}});     

+      //In default JVM territory, 'aacorn' is != 'Acorn'
+      checkLangBasedQuery(ds, "SELECT ID, NAME FROM CUSTOMER where 'aacorn' = 'Acorn' ",
+      		null);
+      //In default JVM territory, 'aacorn' is not < 'Acorn'
+      checkLangBasedQuery(ds, "SELECT ID, NAME FROM CUSTOMER where 'aacorn' < 'Acorn'
",
+      		null);
+      dropTable(ds);
       }
       
   /**
@@ -75,8 +84,19 @@
       DataSource ds = JDBCDataSource.getDataSourceLogical("poldb");
       JDBCDataSource.setBeanProperty(ds, "connectionAttributes", 
                   "create=true;territory=pl;collation=TERRITORY_BASED");
-      checkLangBasedQuery(ds, new String[][] {{"6","aacorn"}, {"4","Acorn"}, {"2","\u0104corn"},
-              {"0","Smith"},{"5","\u015Amith"}, {"1","Zebra"},{"3","\u017Bebra"}});
+      setUpTable(ds);
+      checkLangBasedQuery(ds, "SELECT ID, NAME FROM CUSTOMER ORDER BY NAME",
+      		new String[][] {{"6","aacorn"}, {"4","Acorn"}, {"2","\u0104corn"},
+      		{"0","Smith"},{"5","\u015Amith"}, {"1","Zebra"},{"3","\u017Bebra"}});
+      //In Polish, 'aacorn' is != 'Acorn'
+      checkLangBasedQuery(ds, "SELECT ID, NAME FROM CUSTOMER where 'aacorn' = 'Acorn' ",
+      		null);
+      //In Polish, 'aacorn' is < 'Acorn'
+      checkLangBasedQuery(ds, "SELECT ID, NAME FROM CUSTOMER where 'aacorn' < 'Acorn'",
+      		new String[][] {{"0","Smith"}, {"1","Zebra"}, {"2","\u0104corn"},
+      		{"3","\u017Bebra"}, {"4","Acorn"}, {"5","\u015Amith"}, 
+			{"6","aacorn"}});
+      dropTable(ds);
       }    
   
 
@@ -89,8 +109,17 @@
       DataSource ds = JDBCDataSource.getDataSourceLogical("nordb");
       JDBCDataSource.setBeanProperty(ds, "connectionAttributes", 
                   "create=true;territory=no;collation=TERRITORY_BASED");
-      checkLangBasedQuery(ds, new String[][] {{"4","Acorn"}, {"2","\u0104corn"},{"0","Smith"},
-              {"5","\u015Amith"}, {"1","Zebra"},{"3","\u017Bebra"}, {"6","aacorn"}});
+      setUpTable(ds);
+      checkLangBasedQuery(ds, "SELECT ID, NAME FROM CUSTOMER ORDER BY NAME",
+      		new String[][] {{"4","Acorn"}, {"2","\u0104corn"},{"0","Smith"},
+      		{"5","\u015Amith"}, {"1","Zebra"},{"3","\u017Bebra"}, {"6","aacorn"}});
+      //In Norway, 'aacorn' is != 'Acorn'
+      checkLangBasedQuery(ds, "SELECT ID, NAME FROM CUSTOMER where 'aacorn' = 'Acorn' ",
+      		null);
+      //In Norway, 'aacorn' is not < 'Acorn'
+      checkLangBasedQuery(ds, "SELECT ID, NAME FROM CUSTOMER where 'aacorn' < 'Acorn'
",
+      		null);
+      dropTable(ds);
       }
   
 
@@ -103,37 +132,67 @@
       DataSource ds = JDBCDataSource.getDataSourceLogical("endb");
       JDBCDataSource.setBeanProperty(ds, "connectionAttributes", 
                   "create=true;territory=en;collation=TERRITORY_BASED");
-      checkLangBasedQuery(ds, new String[][] {{"6","aacorn"},{"4","Acorn"},{"2","\u0104corn"},{"0","Smith"},
-               {"5","\u015Amith"},{"1","Zebra"},{"3","\u017Bebra"}});      
+      setUpTable(ds);
+      checkLangBasedQuery(ds, "SELECT ID, NAME FROM CUSTOMER ORDER BY NAME",
+      		new String[][] {{"6","aacorn"},{"4","Acorn"},{"2","\u0104corn"},{"0","Smith"},
+      		{"5","\u015Amith"},{"1","Zebra"},{"3","\u017Bebra"}});      
+      //In English, 'aacorn' != 'Acorn'
+      checkLangBasedQuery(ds, "SELECT ID, NAME FROM CUSTOMER where 'aacorn' = 'Acorn' ",
+      		null);
+      //In English, 'aacorn' is < 'Acorn'
+      checkLangBasedQuery(ds, "SELECT ID, NAME FROM CUSTOMER where 'aacorn' < 'Acorn'",
+      		new String[][] {{"0","Smith"}, {"1","Zebra"}, {"2","\u0104corn"},
+      		{"3","\u017Bebra"}, {"4","Acorn"}, {"5","\u015Amith"}, 
+			{"6","aacorn"}});
+      dropTable(ds);
       }
-  
+
+private void setUpTable(DataSource ds) throws SQLException {
+	Connection conn = ds.getConnection();
+	Statement s = conn.createStatement();
+    s.execute("CREATE TABLE CUSTOMER(ID INT, NAME VARCHAR(40))");
+
+    conn.setAutoCommit(false);
+    PreparedStatement ps = conn.prepareStatement("INSERT INTO CUSTOMER VALUES(?,?)");
+    for (int i = 0; i < NAMES.length; i++)
+    {
+            ps.setInt(1, i);
+            ps.setString(2, NAMES[i]);
+            ps.executeUpdate();
+    }
+
+    conn.commit();
+    ps.close();
+    s.close();
+}
+
+private void dropTable(DataSource ds) throws SQLException {
+	Connection conn = ds.getConnection();
+	Statement s = conn.createStatement();
+	
+    s.execute("DROP TABLE CUSTOMER");     
+    s.close();
+}
 /**
  * sort customers by 
  * @param ds
- * @param expectedResult
+ * @param expectedResult Null for this means that the passed query is 
+ * expected to return an empty resultset. If not empty, then the resultset
+ * from the query should match this paramter
  * @throws SQLException
  */
-private void checkLangBasedQuery(DataSource ds, String[][] expectedResult) throws SQLException
{
+private void checkLangBasedQuery(DataSource ds, String query, String[][] expectedResult)
throws SQLException {
     Connection conn = ds.getConnection();
-      Statement s = conn.createStatement();
-      
-      s.execute("CREATE TABLE CUSTOMER(ID INT, NAME VARCHAR(40))");
-
-      conn.setAutoCommit(false);
-      PreparedStatement ps = conn.prepareStatement("INSERT INTO CUSTOMER VALUES(?,?)");
+    conn.setAutoCommit(false);
 
-      for (int i = 0; i < NAMES.length; i++)
-      {
-              ps.setInt(1, i);
-              ps.setString(2, NAMES[i]);
-              ps.executeUpdate();
-      }
-      
-      ResultSet rs = s.executeQuery("SELECT ID, NAME FROM CUSTOMER ORDER BY NAME");
-      JDBC.assertFullResultSet(rs,expectedResult);
-      s.execute("DROP TABLE CUSTOMER");     
-      conn.commit();
-      ps.close();
+    Statement s = conn.createStatement();
+    ResultSet rs = s.executeQuery(query);
+    if (expectedResult == null) //expecting empty resultset from the query
+    	JDBC.assertEmpty(rs);
+    else
+    	JDBC.assertFullResultSet(rs,expectedResult);
+    s.close();
+    conn.commit();
 }
     
   public static Test suite() {



Mime
View raw message