db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r889975 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Sat, 12 Dec 2009 20:39:48 GMT
Author: rhillegas
Date: Sat Dec 12 20:39:48 2009
New Revision: 889975

URL: http://svn.apache.org/viewvc?rev=889975&view=rev
Log:
DERBY-4469: Allow casting of nulls and ? parameters to UDTs.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java?rev=889975&r1=889974&r2=889975&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java Sat Dec
12 20:39:48 2009
@@ -381,13 +381,11 @@
 		*/
 		if (getTypeId().userType())
 		{
+            setType( bindUserType( getTypeServices() ) );
+            
 			String className = getTypeId().getCorrespondingJavaTypeName();
 
 			verifyClassExist(className);
-
-			setType(new DataTypeDescriptor(TypeId.getUserDefinedTypeId(className, false),
-														true /* assume nullable for now, change it if not nullable */
-													));
 		}
 
         // Obviously the type of a parameter that

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=889975&r1=889974&r2=889975&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Sat Dec
12 20:39:48 2009
@@ -3855,6 +3855,11 @@
 	{
 		return typeDescriptor;
 	}
+|
+	typeDescriptor = javaType()
+	{
+		return typeDescriptor;
+	}
 }
 
 /*
@@ -3897,7 +3902,7 @@
 	typeDescriptor = LOBType()
 |
 	typeDescriptor = XMLType()
-	)
+)
 	{
 		return typeDescriptor;
 	}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out?rev=889975&r1=889974&r2=889975&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
Sat Dec 12 20:39:48 2009
@@ -1685,62 +1685,62 @@
 0 rows inserted/updated/deleted
 ij> -- No support for Java types in CAST statements;
 values CAST (NULL AS CLASS java.lang.Integer);
-ERROR 42X01: Syntax error: Encountered "" at line 3, column 22.
+ERROR 42X01: Syntax error: Encountered "java" at line 3, column 28.
 Issue the 'help' command for general information on IJ command syntax.
 Any unrecognized commands are treated as potential SQL commands and executed directly.
 Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
 ij> values CAST (NULL AS CLASS com.acme.SomeClass);
-ERROR 42X01: Syntax error: Encountered "" at line 1, column 22.
+ERROR 42X01: Syntax error: Encountered "com" at line 1, column 28.
 Issue the 'help' command for general information on IJ command syntax.
 Any unrecognized commands are treated as potential SQL commands and executed directly.
 Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
 ij> values CAST (NULL AS CLASS java.sql.Date);
-ERROR 42X01: Syntax error: Encountered "" at line 1, column 22.
+ERROR 42X01: Syntax error: Encountered "java" at line 1, column 28.
 Issue the 'help' command for general information on IJ command syntax.
 Any unrecognized commands are treated as potential SQL commands and executed directly.
 Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
 ij> values CAST (NULL AS java.lang.Integer);
-ERROR 42X01: Syntax error: Encountered "" at line 1, column 22.
+ERROR 42X01: Syntax error: Encountered "." at line 1, column 31.
 Issue the 'help' command for general information on IJ command syntax.
 Any unrecognized commands are treated as potential SQL commands and executed directly.
 Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
 ij> values CAST (NULL AS com.acme.SomeClass);
-ERROR 42X01: Syntax error: Encountered "" at line 1, column 22.
+ERROR 42X01: Syntax error: Encountered "." at line 1, column 30.
 Issue the 'help' command for general information on IJ command syntax.
 Any unrecognized commands are treated as potential SQL commands and executed directly.
 Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
 ij> values CAST (NULL AS java.sql.Date);
-ERROR 42X01: Syntax error: Encountered "" at line 1, column 22.
+ERROR 42X01: Syntax error: Encountered "sql" at line 1, column 27.
 Issue the 'help' command for general information on IJ command syntax.
 Any unrecognized commands are treated as potential SQL commands and executed directly.
 Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
 ij> values CAST (? AS CLASS java.lang.Integer);
-ERROR 42X01: Syntax error: Encountered "" at line 1, column 19.
+ERROR 42X01: Syntax error: Encountered "java" at line 1, column 25.
 Issue the 'help' command for general information on IJ command syntax.
 Any unrecognized commands are treated as potential SQL commands and executed directly.
 Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
 ij> values CAST (? AS CLASS com.acme.SomeClass);
-ERROR 42X01: Syntax error: Encountered "" at line 1, column 19.
+ERROR 42X01: Syntax error: Encountered "com" at line 1, column 25.
 Issue the 'help' command for general information on IJ command syntax.
 Any unrecognized commands are treated as potential SQL commands and executed directly.
 Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
 ij> values CAST (? AS CLASS java.sql.Date);
-ERROR 42X01: Syntax error: Encountered "" at line 1, column 19.
+ERROR 42X01: Syntax error: Encountered "java" at line 1, column 25.
 Issue the 'help' command for general information on IJ command syntax.
 Any unrecognized commands are treated as potential SQL commands and executed directly.
 Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
 ij> values CAST (? AS java.lang.Integer);
-ERROR 42X01: Syntax error: Encountered "" at line 1, column 19.
+ERROR 42X01: Syntax error: Encountered "." at line 1, column 28.
 Issue the 'help' command for general information on IJ command syntax.
 Any unrecognized commands are treated as potential SQL commands and executed directly.
 Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
 ij> values CAST (? AS com.acme.SomeClass);
-ERROR 42X01: Syntax error: Encountered "" at line 1, column 19.
+ERROR 42X01: Syntax error: Encountered "." at line 1, column 27.
 Issue the 'help' command for general information on IJ command syntax.
 Any unrecognized commands are treated as potential SQL commands and executed directly.
 Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
 ij> values CAST (? AS java.sql.Date);
-ERROR 42X01: Syntax error: Encountered "" at line 1, column 19.
+ERROR 42X01: Syntax error: Encountered "sql" at line 1, column 24.
 Issue the 'help' command for general information on IJ command syntax.
 Any unrecognized commands are treated as potential SQL commands and executed directly.
 Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java?rev=889975&r1=889974&r2=889975&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
Sat Dec 12 20:39:48 2009
@@ -429,15 +429,8 @@
         goodStatement
             (
              conn,
-             "create function makePrice_05( )\n" +
-             "returns price_05_a language java parameter style java no sql\n" +
-             "external name 'org.apache.derbyTesting.functionTests.tests.lang.Price.makePrice'\n"
-              );
-        goodStatement
-            (
-             conn,
              "create view udtView( a, b, c ) as\n" +
-             "select tabletype, makePrice_05( ), makePrice_05( )\n" +
+             "select tabletype, cast (null as price_05_a), cast( null as price_05_a)\n" +
              "from sys.systables\n"
               );
         expectExecutionError( conn, VIEW_DEPENDS_ON_TYPE, "drop type price_05_a restrict\n"
);
@@ -455,15 +448,8 @@
         goodStatement
             (
              conn,
-             "create function makePrice_05_b( )\n" +
-             "returns price_05_b language java parameter style java no sql\n" +
-             "external name 'org.apache.derbyTesting.functionTests.tests.lang.Price.makePrice'\n"
-              );
-        goodStatement
-            (
-             conn,
              "create view udtView_b( a ) as\n" +
-             "select tabletype from sys.systables where makePrice_05_b() is not null\n"
+             "select tabletype from sys.systables where ( cast (null as price_05_b) ) is
not null\n"
               );
         expectExecutionError( conn, VIEW_DEPENDS_ON_TYPE, "drop type price_05_b restrict\n"
);
         goodStatement
@@ -475,6 +461,42 @@
 
     }
 
+    /**
+     * <p>
+     * Casting to UDTs.
+     * </p>
+     */
+    public void test_06_casts() throws Exception
+    {
+        Connection conn = getConnection();
+
+        // cast a NULL as a UDT
+        goodStatement
+            ( conn,
+              "create type price_06_b external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java\n" );
+        assertResults
+            (
+             conn,
+             "values ( cast ( null as price_06_b ) )\n",
+             new String[][]
+             {
+                 { null },
+             },
+             false
+             );
+
+        // casting an untyped parameter to a UDT
+        PreparedStatement ps = chattyPrepare
+            ( conn, "values ( cast ( ? as price_06_b ) )" );
+        ps.setObject( 1, Price.makePrice() );
+        ResultSet rs = ps.executeQuery();
+        rs.next();
+        Price result = (Price) rs.getObject( 1 );
+        rs.close();
+        ps.close();
+        assertTrue( Price.makePrice().equals( result ) );
+    }
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // MINIONS



Mime
View raw message