db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r567741 - in /db/derby/code/branches/10.3/java: engine/org/apache/derby/iapi/types/ engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/impl/sql/execute/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Mon, 20 Aug 2007 16:23:59 GMT
Author: mamta
Date: Mon Aug 20 09:23:58 2007
New Revision: 567741

URL: http://svn.apache.org/viewvc?rev=567741&view=rev
Log:
Merging revision 567735 from main into 10.3 codeline. The commit comments in main were as
follows

DERBY-2961
This commit fixes the ASSERT failure thrown by the SELECT statement in following query
CREATE TABLE T_MAIN1 (ID INT  GENERATED ALWAYS AS IDENTITY PRIMARY KEY, V XML);
INSERT INTO T_MAIN1(V) VALUES NULL;
SELECT ID, XMLSERIALIZE(V AS CLOB), XMLSERIALIZE(V AS CLOB) FROM T_MAIN1 ORDER BY 1;
The SELECT statement was resulting in Assert Failure because the StringDataValue generated
for V AS CLOB was not taking collation type into consideration ie it was always generating
collation insensitive StringDataValue. I have fixed that problem by passing the current compilation
schema's collation type to SqlXmlExecutor which then will get used in determining whether
for instance we should generate SQLChar vs CollatorSQLChar. This collation information is
required only for character string types.


Modified:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/XML.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/XMLDataValue.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/SqlXmlExecutor.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/XML.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/XML.java?rev=567741&r1=567740&r2=567741&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/XML.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/XML.java Mon Aug 20
09:23:58 2007
@@ -31,6 +31,7 @@
 import org.apache.derby.iapi.services.io.TypedFormat;
 import org.apache.derby.iapi.services.loader.ClassInspector;
 import org.apache.derby.iapi.services.sanity.SanityManager;
+import org.apache.derby.iapi.sql.conn.ConnectionUtil;
 
 import org.apache.derby.iapi.types.DataValueDescriptor;
 import org.apache.derby.iapi.types.StringDataValue;
@@ -41,6 +42,7 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Types;
+import java.text.RuleBasedCollator;
 
 import java.io.InputStream;
 import java.io.IOException;
@@ -674,7 +676,8 @@
      * @exception StandardException    Thrown on error
      */
     public StringDataValue XMLSerialize(StringDataValue result,
-        int targetType, int targetWidth) throws StandardException
+        int targetType, int targetWidth, int targetCollationType) 
+    throws StandardException
     {
         if (result == null) {
             switch (targetType)
@@ -694,6 +697,30 @@
                     }
                     return null;
             }
+            // If the collation type is territory based, then we should use
+            // CollatorSQLxxx rather than SQLxxx types for StringDataValue. 
+            // eg
+            // CREATE TABLE T_MAIN1 (ID INT  GENERATED ALWAYS AS IDENTITY 
+            //       PRIMARY KEY, V XML);
+            // INSERT INTO T_MAIN1(V) VALUES NULL;
+            // SELECT ID, XMLSERIALIZE(V AS CLOB), XMLSERIALIZE(V AS CLOB) 
+            //       FROM T_MAIN1 ORDER BY 1;
+            // Following code is for (V AS CLOB) inside XMLSERIALIZE. The
+            // StringDataValue returned for (V AS CLOB) should consider the 
+            // passed collation type in determining whether we should
+            // generate SQLChar vs CollatorSQLChar for instance. Keep in mind
+            // that collation applies only to character string types.
+    		if (result instanceof StringDataValue) {
+    			try {
+    				RuleBasedCollator rbs = ConnectionUtil.getCurrentLCC().getDataValueFactory().
+    				getCharacterCollator(targetCollationType);
+    				result = ((StringDataValue)result).getValue(rbs);
+    			}
+    			catch( java.sql.SQLException sqle)
+    			{
+    				throw StandardException.plainWrapException( sqle);
+    			}
+    		}
         }
 
         // Else we're reusing a StringDataValue.  We only reuse

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/XMLDataValue.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/XMLDataValue.java?rev=567741&r1=567740&r2=567741&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/XMLDataValue.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/XMLDataValue.java
Mon Aug 20 09:23:58 2007
@@ -56,12 +56,14 @@
      *  null if not called yet.
      * @param targetType The string type to which we want to serialize.
      * @param targetWidth The width of the target type.
+     * @param targetCollationType The collation type of the target type.
      * @return A serialized (to string) version of this XML object,
      *  in the form of a StringDataValue object.
      * @exception StandardException Thrown on error
      */
     public StringDataValue XMLSerialize(StringDataValue result,
-        int targetType, int targetWidth) throws StandardException;
+        int targetType, int targetWidth, int targetCollationType) 
+    throws StandardException;
 
     /**
      * The SQL/XML XMLExists operator.

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java?rev=567741&r1=567740&r2=567741&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java
Mon Aug 20 09:23:58 2007
@@ -791,11 +791,17 @@
         // the serialized version of the XML value, which we
         // already found when the XML value was created (ex.
         // as part of the XMLPARSE work).
+        // We also need to pass the collation type of the current
+        // compilation schema. If the JDBC type id is of type
+        // StringDataValue, then we should use the collation to
+        // decide whether we need to generate collation sensitive
+        // StringDataValue.
             DataTypeDescriptor targetType =
                 (DataTypeDescriptor)additionalArgs[0];
             mb.push(targetType.getJDBCTypeId());
             mb.push(targetType.getMaximumWidth());
-            return 2;
+            mb.push(getSchemaDescriptor(null, false).getCollationType());
+            return 3;
         }
 
         /* Else we're here for XMLPARSE. */

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/SqlXmlExecutor.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/SqlXmlExecutor.java?rev=567741&r1=567740&r2=567741&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/SqlXmlExecutor.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/SqlXmlExecutor.java
Mon Aug 20 09:23:58 2007
@@ -126,10 +126,11 @@
     private Activation activation;
     private int sqlXUtilId;
 
-    // Target type and target width that were specified
-    // for an XMLSERIALIZE operator.
+    // Target type, target width and target collation type that 
+    // were specified for an XMLSERIALIZE operator.
     private int targetTypeId;
     private int targetMaxWidth;
+    private int targetCollationType;
 
     // Whether or not to preserve whitespace for XMLPARSE
     // operator.
@@ -153,11 +154,14 @@
      * Constructor 2: Used for XMLSERIALIZE op.
      * @param targetTypeId The string type to which we want to serialize.
      * @param targetMaxWidth The max width of the target type.
+     * @param targetCollationType The collation type of the target type.
      */
-    public SqlXmlExecutor(int targetTypeId, int targetMaxWidth)
+    public SqlXmlExecutor(int targetTypeId, int targetMaxWidth, 
+    		int targetCollationType)
     {
         this.targetTypeId = targetTypeId;
         this.targetMaxWidth = targetMaxWidth;
+        this.targetCollationType = targetCollationType;
     }
 
     /**
@@ -213,7 +217,8 @@
     public StringDataValue XMLSerialize(XMLDataValue xmlVal,
         StringDataValue result) throws StandardException
     {
-        return xmlVal.XMLSerialize(result, targetTypeId, targetMaxWidth);
+        return xmlVal.XMLSerialize(result, targetTypeId, targetMaxWidth, 
+        		targetCollationType);
     }
 
     /**

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java?rev=567741&r1=567740&r2=567741&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
(original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Mon Aug 20 09:23:58 2007
@@ -524,7 +524,7 @@
     //The query below will work for the same reason. 
     checkLangBasedQuery(s, "SELECT count(*) FROM SYS.SYSTABLES WHERE CASE " +
     		" WHEN 1=1 THEN TABLENAME ELSE TABLEID END = TABLENAME",
-    		new String[][] {{"21"} });   
+    		new String[][] {{"22"} });   
 
     //Do some testing using CONCATENATION
     //following will fail because result string of concatenation has 
@@ -992,6 +992,18 @@
     s.execute("CREATE INDEX DERBY_2973_I1 ON DERBY_2973 (V)");
     s.execute("ALTER TABLE DERBY_2973 ALTER V SET DATA TYPE VARCHAR(4096)");
     s.execute("INSERT INTO DERBY_2973 VALUES('hello')");
+    
+    //DERBY-2961
+    //Should generate collation sensitive data type when working with something
+    //like V AS CLOB insdie XMLSERIALIZE as shown below 
+    //SELECT ID, XMLSERIALIZE(V AS CLOB), XMLSERIALIZE(V AS CLOB) FROM 
+    //    DERBY_2961 ORDER BY 1
+    s.executeUpdate("set schema APP");
+    if (XML.classpathMeetsXMLReqs()) {
+        checkLangBasedQuery(s, "SELECT ID, XMLSERIALIZE(V AS CLOB) " +
+        		" FROM DERBY_2961 ORDER BY 1",
+        		null);
+    }
     s.close();
  
 }
@@ -1013,6 +1025,10 @@
 
     s.execute("create table xmlTable (x xml)");
     s.executeUpdate("insert into xmlTable values(null)");
+
+    s.execute("create table DERBY_2961 (ID INT  GENERATED ALWAYS AS " +
+    		" IDENTITY PRIMARY KEY, V XML)");
+    s.executeUpdate("insert into DERBY_2961(V) values(null)");
     
     conn.commit();
     ps.close();



Mime
View raw message