db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r957650 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Date Thu, 24 Jun 2010 17:45:44 GMT
Author: rhillegas
Date: Thu Jun 24 17:45:44 2010
New Revision: 957650

URL: http://svn.apache.org/viewvc?rev=957650&view=rev
Log:
DERBY-4659: Allow BOOLEAN args in procedures.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.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/tests/jdbcapi/DatabaseMetaDataTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMetaDataJdbc30Test.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=957650&r1=957649&r2=957650&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
Thu Jun 24 17:45:44 2010
@@ -1108,6 +1108,7 @@ abstract class MethodCallNode extends Ja
 						// as it (incorrectly but historically always has) maps a DECIMAL to a double. 
 
 						switch (ctid.getJDBCTypeId()) {
+						case java.sql.Types.BOOLEAN:
 						case java.sql.Types.SMALLINT:
 						case java.sql.Types.INTEGER:
 						case java.sql.Types.BIGINT:

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java?rev=957650&r1=957649&r2=957650&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
Thu Jun 24 17:45:44 2010
@@ -457,6 +457,7 @@ public class StaticMethodCallNode extend
 
 					String arrayType;
 					switch (typeId.getJDBCTypeId()) {
+						case java.sql.Types.BOOLEAN:
 						case java.sql.Types.SMALLINT:
 						case java.sql.Types.INTEGER:
 						case java.sql.Types.BIGINT:

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=957650&r1=957649&r2=957650&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 Thu Jun
24 17:45:44 2010
@@ -10778,7 +10778,7 @@ procedureParameterDefinition(Vector[] li
 	[   LOOKAHEAD( { dataTypeCheck(2) })
 	    parameterName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true)
 	]
-	typeDescriptor = dataTypeDDL( false )
+	typeDescriptor = dataTypeDDL( true )
 	{
 		list[0].addElement(parameterName);
 		list[1].addElement(typeDescriptor.getCatalogType());

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java?rev=957650&r1=957649&r2=957650&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
Thu Jun 24 17:45:44 2010
@@ -4370,8 +4370,12 @@ public class DatabaseMetaDataTest extend
     // Possible TODO: 
     //   rewrite data portion of this test to compare results from 
     //   metadata with sys.sys* query results (leave shape check in place)
-    public void testGetProceduresGetProcColumns() throws SQLException {
-        
+    public void testGetProceduresGetProcColumns() throws Exception {
+
+        boolean supportsBoolean = true;
+        Version dataVersion = getDataVersion( getConnection() );
+        if ( dataVersion.compareTo( new Version( 10, 7, 0, 0 ) ) < 0 ) { supportsBoolean
= false; }
+
         Statement s = createStatement();
         getConnection().setAutoCommit(false);
         
@@ -4406,7 +4410,15 @@ public class DatabaseMetaDataTest extend
         s.execute("create procedure GETPCTEST4Bx(out retparam INTEGER) "+
                 "language java external name " +
                 "'org.apache.derbyTesting.functionTests.tests.jdbcapi.DatabaseMetaDataTest.getpc4b'"
+
-        " parameter style java"); 
+        " parameter style java");
+
+        if ( supportsBoolean )
+        {
+            s.execute("create procedure GETPCTEST5(in inarg boolean, out outarg boolean,
inout inoutarg boolean) "+
+                      "language java external name " +
+                      "'org.apache.derbyTesting.functionTests.tests.jdbcapi.DatabaseMetaDataTest.foo'"
+
+                      " parameter style java");
+        }
         
         ResultSet rs[] = getProcedures(null, "%", "GETPCTEST%");
         String[][] expRS = new String[][] {
@@ -4418,10 +4430,22 @@ public class DatabaseMetaDataTest extend
                 {"","APP","GETPCTEST4B","null","null","null","getpc4b","1"},
                 {"","APP","GETPCTEST4BX","null","null","null","getpc4b","1"},
         };
+
+        if ( supportsBoolean )
+        {
+            expRS = appendArray
+                (
+                 expRS,
+                 new String[][]
+                 {
+                     {"","APP","GETPCTEST5","null","null","null","foo","1"},
+                 }
+                 );
+        }
         for (int j=0 ; j<2 ; j++)
         {
             int rowcount = 0;
-            while (rowcount < 7){
+            while (rowcount < expRS.length){
                 rs[j].next();
                 assertEquals(expRS[rowcount][0], rs[j].getString(1));
                 assertEquals(expRS[rowcount][1], rs[j].getString(2));
@@ -4457,12 +4481,25 @@ public class DatabaseMetaDataTest extend
                 {null,"APP","GETPCTEST3A","STRING2","4","12","VARCHAR","5","10",null,null,"1",null,null,"12",null,"10","2","YES","genid","2","1"},
                 {null,"APP","GETPCTEST3B","STRING3","1","12","VARCHAR","5","10",null,null,"1",null,null,"12",null,"10","1","YES","genid","2","0"},
                 {null,"APP","GETPCTEST3B","STRING4","2","12","VARCHAR","5","10",null,null,"1",null,null,"12",null,"10","2","YES","genid","2","1"},
-                {null,"APP","GETPCTEST4BX","RETPARAM","4","4","INTEGER","10","4","0","10","1",null,null,"4",null,null,"1","YES","genid","1","0"}
+                {null,"APP","GETPCTEST4BX","RETPARAM","4","4","INTEGER","10","4","0","10","1",null,null,"4",null,null,"1","YES","genid","1","0"},
         };
+        if ( supportsBoolean )
+        {
+            expRS = appendArray
+                (
+                 expRS,
+                 new String[][]
+                 {
+                     {null,"APP","GETPCTEST5","INARG","1","16","BOOLEAN","1","1",null,null,"1",null,null,"16",null,null,"1","YES","genid","3","0"},
+                     {null,"APP","GETPCTEST5","OUTARG","4","16","BOOLEAN","1","1",null,null,"1",null,null,"16",null,null,"2","YES","genid","3","1"},
+                     {null,"APP","GETPCTEST5","INOUTARG","2","16","BOOLEAN","1","1",null,null,"1",null,null,"16",null,null,"3","YES","genid","3","2"},
+                 }
+                 );
+        }
         for (int j=0 ; j<2 ; j++)
         {
             int rowcount = 0;
-            while (rowcount < 19){
+            while (rowcount < expRS.length){
                 rs[j].next();
                 for (int k=0 ; k<19 ; k++){
                     if (j == 0 && (k == 14 || k == 15))
@@ -4495,6 +4532,7 @@ public class DatabaseMetaDataTest extend
             }
         }
         
+        if ( supportsBoolean ) { s.execute("drop procedure GETPCTEST5"); }
         s.execute("drop procedure GETPCTEST4Bx");
         s.execute("drop procedure GETPCTEST4B");
         s.execute("drop procedure GETPCTEST4A");
@@ -4504,6 +4542,20 @@ public class DatabaseMetaDataTest extend
         s.execute("drop procedure GETPCTEST1");
         commit();
     }
+    private String[][] appendArray( String[][] target, String[][] suffix )
+    {
+        int targetLength = target.length;
+        int suffixLength = suffix.length;
+        int resultLength = targetLength + suffixLength;
+
+        String[][] result = new String[ resultLength ][];
+        for ( int i = 0; i < targetLength; i++ ) { result[ i ] = target[ i ]; }
+        for ( int i = 0; i < suffixLength; i++ ) { result[ targetLength + i ] = suffix[
i ]; }
+
+        println( "Appended array" );
+
+        return result;
+    }
 
     /**
      * Helper method for testing getProcedures - calls the ODBC procedure

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMetaDataJdbc30Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMetaDataJdbc30Test.java?rev=957650&r1=957649&r2=957650&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMetaDataJdbc30Test.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMetaDataJdbc30Test.java
Thu Jun 24 17:45:44 2010
@@ -281,6 +281,56 @@ public class ParameterMetaDataJdbc30Test
 		ps.close();
 	}
 
+    /**
+     * Testing a callable statement by calling a SQL procedure with 
+     * boolean IN parameters, OUT parameters and IN_OUT parameters.
+     */
+	public void testBooleanProcedureArgs() throws Exception
+    {
+        Statement stmt = createStatement();
+
+        stmt.executeUpdate("create procedure booleanProc" + 
+                           "( in inarg boolean, out outarg boolean, inout inoutarg boolean
)" + 
+                           "language java external name "+ 
+                           "'org.apache.derbyTesting.functionTests." +
+                           "tests.jdbcapi.ParameterMetaDataJdbc30Test.booleanProc' " +
+                           "parameter style java");
+        
+        CallableStatement cs = prepareCall("CALL booleanProc(?,?,?)");
+        cs.registerOutParameter(2,Types.BOOLEAN);
+        cs.registerOutParameter(3,Types.BOOLEAN);
+
+        //verify the meta data for the parameters
+        ParameterMetaData paramMetaData = cs.getParameterMetaData();
+		assertEquals("Unexpected parameter count", 3, paramMetaData.getParameterCount());
+        
+		//expected values to be stored in a 2dim. array	
+		String [][] parameterMetaDataArray0 =
+            {
+                //isNullable, isSigned, getPrecision, getScale, getParameterType, getParameterTypeName,
getParameterClassName, getParameterMode
+                {"PARAMETER_NULLABLE", "false", "1", "0", "16", "BOOLEAN", "java.lang.Boolean",
"PARAMETER_MODE_IN"},
+                {"PARAMETER_NULLABLE", "false", "1", "0", "16", "BOOLEAN", "java.lang.Boolean",
"PARAMETER_MODE_OUT"},
+                {"PARAMETER_NULLABLE", "false", "1", "0", "16", "BOOLEAN", "java.lang.Boolean",
"PARAMETER_MODE_IN_OUT"},
+            };
+        
+		testParameterMetaData(paramMetaData, parameterMetaDataArray0);
+
+        cs.setBoolean( 1,  true );
+        cs.setBoolean( 3, true );
+        cs.execute();
+        assertEquals( true, cs.getBoolean( 2 ) );
+        assertEquals( false, cs.getBoolean( 3 ) );
+
+        cs.setObject( 1,  Boolean.FALSE );
+        cs.setObject( 3, Boolean.FALSE );
+        cs.execute();
+        assertEquals( false, cs.getBoolean( 2 ) );
+        assertEquals( true, cs.getBoolean( 3 ) );
+
+		stmt.close();
+		cs.close();
+	}
+
 	/** 
 	 * DERBY-44 added support for SELECT ... WHERE column LIKE ? ESCAPE ?
          * This test case tests
@@ -850,4 +900,11 @@ public class ParameterMetaDataJdbc30Test
          */
         public static void dummyDecimal(BigDecimal in_param, BigDecimal in_param2, BigDecimal[]
in_param3, BigDecimal[] in_param4) {
 	 }
+
+    /** Java method for testing procedures with boolean args */
+    public static void booleanProc( boolean inarg, boolean[] outarg, boolean[] inoutarg )
+    {
+        outarg[ 0 ] = inarg;
+        inoutarg[ 0 ] = !inoutarg[ 0 ];
+    }
 }



Mime
View raw message