db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r598069 - in /db/derby/code/branches/10.3/java: engine/org/apache/derby/impl/sql/compile/MethodCallNode.java testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java
Date Sun, 25 Nov 2007 22:11:15 GMT
Author: dag
Date: Sun Nov 25 14:11:15 2007
New Revision: 598069

URL: http://svn.apache.org/viewvc?rev=598069&view=rev
Log:
DERBY-3119  Derby does not resolve functions to methods with Integer return type.

Committed DERBY-3119-10_3.diff, which is a modified version of svn
589766, since that patch didn't apply cleanly due to other changes on
trunk (VTIs). I verified that the new test in RoutineTest failed
without the patch in MethodCallNode and worked when it was applied. 

Modified:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java?rev=598069&r1=598068&r2=598069&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java
Sun Nov 25 14:11:15 2007
@@ -696,34 +696,27 @@
 			}
 			else
 			{
+				TypeId returnTypeId = TypeId.getBuiltInTypeId(returnType.getJDBCTypeId());
 
+				requiredType = returnTypeId.getCorrespondingJavaTypeName();
 
-				// DB2 LUW does not support Java object types for SMALLINT, INTEGER, BIGINT, REAL, DOUBLE
-				// and these are the only types that can map to a primitive or an object type according
-				// to SQL part 13. So always map to the primitive type. We can not use the getPrimitiveSignature()
-				// as it (incorrectly but historically always has) maps a DECIMAL to a double. 
-
-				
-				TypeId returnTypeId = TypeId.getBuiltInTypeId(returnType.getJDBCTypeId());
-				switch (returnType.getJDBCTypeId()) {
-				case java.sql.Types.SMALLINT:
-				case java.sql.Types.INTEGER:
-				case java.sql.Types.BIGINT:
-				case java.sql.Types.REAL:
-				case java.sql.Types.DOUBLE:
-					TypeCompiler tc = getTypeCompiler(returnTypeId);
-					requiredType = tc.getCorrespondingPrimitiveTypeName();
-					if (!routineInfo.calledOnNullInput() && routineInfo.getParameterCount() != 0)
-					{
-						promoteName = returnTypeId.getCorrespondingJavaTypeName();
+				if (!requiredType.equals(typeName)) {
+					switch (returnType.getJDBCTypeId()) {
+					case java.sql.Types.SMALLINT:
+					case java.sql.Types.INTEGER:
+					case java.sql.Types.BIGINT:
+					case java.sql.Types.REAL:
+					case java.sql.Types.DOUBLE:
+						TypeCompiler tc = getTypeCompiler(returnTypeId);
+						requiredType = tc.getCorrespondingPrimitiveTypeName();
+						if (!routineInfo.calledOnNullInput() && 
+								routineInfo.getParameterCount() != 0) {
+							promoteName = returnTypeId.getCorrespondingJavaTypeName();
+						}
+						
+						break;
 					}
-
-					break;
-				default:
-					requiredType = returnTypeId.getCorrespondingJavaTypeName();
-					break;
 				}
-
 			}
 
 			if (!requiredType.equals(typeName))

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java?rev=598069&r1=598068&r2=598069&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java
(original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java
Sun Nov 25 14:11:15 2007
@@ -55,6 +55,119 @@
         return new CleanDatabaseTestSetup(suite);
     }
     
+    
+    /**
+     * Test that function result data types are resolved correctly for numeric
+     * types that Derby supports that are simply mappable or object mappable.
+     */
+    public void testFunctionResultDataTypeValidation() throws SQLException
+    {
+        Statement s = createStatement();
+
+        // SMALLINT -> short
+        s.executeUpdate(
+        "CREATE FUNCTION SMALLINT_P_SHORT(VARCHAR(10)) RETURNS SMALLINT " +
+           "EXTERNAL NAME 'java.lang.Short.parseShort' " +
+           "LANGUAGE JAVA PARAMETER STYLE JAVA");
+
+        PreparedStatement ps = prepareStatement("VALUES SMALLINT_P_SHORT(?)");
+        ps.setString(1, "123");
+        JDBC.assertSingleValueResultSet(ps.executeQuery(), "123");  
+
+        // SMALLINT -> Integer
+        s.executeUpdate(
+        "CREATE FUNCTION SMALLINT_O_INTEGER(VARCHAR(10)) RETURNS SMALLINT " +
+           "EXTERNAL NAME 'java.lang.Integer.valueOf' " +
+           "LANGUAGE JAVA PARAMETER STYLE JAVA");
+
+        ps = prepareStatement("VALUES SMALLINT_O_INTEGER(?)");
+        ps.setString(1, "123");
+        JDBC.assertSingleValueResultSet(ps.executeQuery(), "123");  
+
+        // INTEGER -> int
+        s.executeUpdate(
+        "CREATE FUNCTION INTEGER_P_INT(VARCHAR(10)) RETURNS INTEGER " +
+           "EXTERNAL NAME 'java.lang.Integer.parseInt' " +
+           "LANGUAGE JAVA PARAMETER STYLE JAVA");
+
+        ps = prepareStatement("VALUES INTEGER_P_INT(?)");
+        ps.setString(1, "123");
+        JDBC.assertSingleValueResultSet(ps.executeQuery(), "123");  
+
+        // INTEGER -> Integer
+        s.executeUpdate(
+        "CREATE FUNCTION INTEGER_O_INTEGER(VARCHAR(10)) RETURNS INTEGER " +
+           "EXTERNAL NAME 'java.lang.Integer.valueOf' " +
+           "LANGUAGE JAVA PARAMETER STYLE JAVA");
+
+        ps = prepareStatement("VALUES INTEGER_O_INTEGER(?)");
+        ps.setString(1, "123");
+        JDBC.assertSingleValueResultSet(ps.executeQuery(), "123");  
+
+        // BIGINT -> long
+        s.executeUpdate(
+        "CREATE FUNCTION BIGINT_P_LONG(VARCHAR(10)) RETURNS BIGINT " +
+           "EXTERNAL NAME 'java.lang.Long.parseLong' " +
+           "LANGUAGE JAVA PARAMETER STYLE JAVA");
+
+        ps = prepareStatement("VALUES BIGINT_P_LONG(?)");
+        ps.setString(1, "123");
+        JDBC.assertSingleValueResultSet(ps.executeQuery(), "123");  
+
+        // BIGINT -> Long
+        s.executeUpdate(
+        "CREATE FUNCTION BIGINT_O_LONG(VARCHAR(10)) RETURNS BIGINT " +
+           "EXTERNAL NAME 'java.lang.Long.valueOf' " +
+           "LANGUAGE JAVA PARAMETER STYLE JAVA");
+
+        ps = prepareStatement("VALUES BIGINT_O_LONG(?)");
+        ps.setString(1, "123");
+        JDBC.assertSingleValueResultSet(ps.executeQuery(), "123");  
+
+        // REAL -> float
+        s.executeUpdate(
+        "CREATE FUNCTION REAL_P_FLOAT(VARCHAR(10)) RETURNS REAL " +
+           "EXTERNAL NAME 'java.lang.Float.parseFloat' " +
+           "LANGUAGE JAVA PARAMETER STYLE JAVA");
+
+        ps = prepareStatement("VALUES REAL_P_FLOAT(?)");
+        ps.setString(1, "123.0");
+        JDBC.assertSingleValueResultSet(ps.executeQuery(), "123.0");  
+
+        // REAL -> Float
+        s.executeUpdate(
+        "CREATE FUNCTION REAL_O_FLOAT(VARCHAR(10)) RETURNS REAL " +
+           "EXTERNAL NAME 'java.lang.Float.valueOf' " +
+           "LANGUAGE JAVA PARAMETER STYLE JAVA");
+
+        ps = prepareStatement("VALUES REAL_O_FLOAT(?)");
+        ps.setString(1, "123.0");
+        JDBC.assertSingleValueResultSet(ps.executeQuery(), "123.0");  
+
+        // DOUBLE -> double
+        s.executeUpdate(
+        "CREATE FUNCTION DOUBLE_P_DOUBLE(VARCHAR(10)) RETURNS DOUBLE " +
+           "EXTERNAL NAME 'java.lang.Double.parseDouble' " +
+           "LANGUAGE JAVA PARAMETER STYLE JAVA");
+
+        ps = prepareStatement("VALUES DOUBLE_P_DOUBLE(?)");
+        ps.setString(1, "123.0");
+        JDBC.assertSingleValueResultSet(ps.executeQuery(), "123.0");  
+
+        // DOBULE -> Double
+        s.executeUpdate(
+        "CREATE FUNCTION DOUBLE_O_DOUBLE(VARCHAR(10)) RETURNS DOUBLE " +
+           "EXTERNAL NAME 'java.lang.Double.valueOf' " +
+           "LANGUAGE JAVA PARAMETER STYLE JAVA");
+
+        ps = prepareStatement("VALUES DOUBLE_O_DOUBLE(?)");
+        ps.setString(1, "123.0");
+        JDBC.assertSingleValueResultSet(ps.executeQuery(), "123.0");
+        
+        ps.close();
+        s.close();
+    }
+    
     /**
      * Test that functions handle being called or not called
      * when it is passed a NULL argument correctly.



Mime
View raw message