db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r589766 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/MethodCallNode.java testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java
Date Mon, 29 Oct 2007 17:43:36 GMT
Author: rhillegas
Date: Mon Oct 29 10:43:34 2007
New Revision: 589766

URL: http://svn.apache.org/viewvc?rev=589766&view=rev
Log:
DERBY-3119: Commit James Adams patch for resolving functions which return the Java object
versions of the primitive datatypes.

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

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java?rev=589766&r1=589765&r2=589766&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java
Mon Oct 29 10:43:34 2007
@@ -792,14 +792,6 @@
 			}
 			else
 			{
-
-
-				// 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());
 
 				if (
@@ -811,24 +803,24 @@
 				}
 				else
 				{
-				    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();
-				    	}
+			 		requiredType = returnTypeId.getCorrespondingJavaTypeName();
 
-				    	break;
-				    default:
-				    	requiredType = returnTypeId.getCorrespondingJavaTypeName();
-				    	break;
-				    }
+					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;
+						}
+					}
 				}
 			}
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java?rev=589766&r1=589765&r2=589766&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RoutineTest.java
Mon Oct 29 10:43:34 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