db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1186020 - in /db/derby/code/trunk/java: client/org/apache/derby/client/net/NetStatementRequest.java testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/JDBCDriverTest.java
Date Wed, 19 Oct 2011 08:14:32 GMT
Author: kahatlen
Date: Wed Oct 19 08:14:32 2011
New Revision: 1186020

URL: http://svn.apache.org/viewvc?rev=1186020&view=rev
Log:
DERBY-5449: 10.8 client with 10.5 server gives ClassCastException

Convert BOOLEAN parameter values to SMALLINT (and not only the parameter
meta-data) when talking to old servers that don't understand BOOLEAN.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/JDBCDriverTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java?rev=1186020&r1=1186019&r2=1186020&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java Wed
Oct 19 08:14:32 2011
@@ -1229,8 +1229,15 @@ public class NetStatementRequest extends
                     }
                     else
                     {
+                        // If the server doesn't support BOOLEAN parameters,
+                        // send the parameter as a SMALLINT instead.
                         lidAndLengths[i][0] = DRDAConstants.DRDA_TYPE_NSMALL;
                         lidAndLengths[i][1] = 2;
+                        if (inputRow[i] instanceof Boolean) {
+                            Boolean bool = (Boolean) inputRow[i];
+                            inputRow[i] = new Short(
+                                    bool.booleanValue() ? (short) 1 : 0);
+                        }
                     }
                     break;
                 case java.sql.Types.SMALLINT:

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/JDBCDriverTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/JDBCDriverTest.java?rev=1186020&r1=1186019&r2=1186020&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/JDBCDriverTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/JDBCDriverTest.java
Wed Oct 19 08:14:32 2011
@@ -32,6 +32,8 @@ import java.io.*;
 import java.math.*;
 import java.sql.*;
 import java.util.*;
+import java.util.regex.Pattern;
+import org.apache.derbyTesting.junit.JDBC;
 
 public	class	JDBCDriverTest	extends	CompatibilitySuite
 {
@@ -254,6 +256,7 @@ public	class	JDBCDriverTest	extends	Comp
         derby_2602_test( conn );
         derby_4613_test( conn );
         derby_4888_test( conn );
+        derby_5449_test( conn );
 
 		close( conn );
 	}
@@ -381,7 +384,39 @@ public	class	JDBCDriverTest	extends	Comp
         // Used to get a ClassCastException here in some combinations.
         assertFalse(conn.getMetaData().storesLowerCaseIdentifiers());
     }
-    
+
+    /**
+     * A pattern that matches the value returned by
+     * DatabaseMetaData.getDriverVersion() for the versions that suffer
+     * from DERBY-5449. That is, all version on the 10.8 branch up to 10.8.2.2.
+     */
+    private static Pattern DERBY_5449_PATTERN = Pattern.compile(
+            "^10\\.8\\.([01]\\.|2\\.[012] ).*");
+
+    /**
+     * Test case for DERBY-5449. Verify that PreparedStatement.setBoolean()
+     * works across different versions. Used to fail with a ClassCastException
+     * when talking to servers at version 10.7 and earlier.
+     */
+    private void derby_5449_test(Connection conn) throws SQLException {
+        if (usingDerbyClient() &&
+                getServerVersion().compareTo(DRB_10_7) <= 0) {
+            // Derby's client drivers on the 10.8 branch up to 10.8.2.2
+            // suffered from DERBY-5449 and the test case will fail when
+            // talking to older servers. Skip the test case in such cases.
+            String driverVersion = conn.getMetaData().getDriverVersion();
+            if (DERBY_5449_PATTERN.matcher(driverVersion).matches()) {
+                return;
+            }
+        }
+
+        PreparedStatement ps = prepare(conn, "VALUES CAST(? AS INTEGER)");
+        ps.setBoolean(1, true);
+        JDBC.assertSingleValueResultSet(ps.executeQuery(), "1");
+        ps.setBoolean(1, false);
+        JDBC.assertSingleValueResultSet(ps.executeQuery(), "0");
+    }
+
 	/////////////////////////////////////////////////////////////
     //
 	//	TEST UDTs



Mime
View raw message