MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:mmatthews Date:November 16 2007 4:31pm
Subject:Connector/J commit: r6666 - in branches/branch_5_0: . src/com/mysql/jdbc src/testsuite/regression
View as plain text  
Modified:
   branches/branch_5_0/CHANGES
   branches/branch_5_0/src/com/mysql/jdbc/PreparedStatement.java
   branches/branch_5_0/src/testsuite/regression/StatementRegressionTest.java
Log:
Fixed an issue where PreparedStatement.setObject(int, Object, int)
      didn't handle String values of "1" or "0" for the target SQL type
      of BIT properly.

Modified: branches/branch_5_0/CHANGES
===================================================================
--- branches/branch_5_0/CHANGES	2007-11-16 15:33:46 UTC (rev 6665)
+++ branches/branch_5_0/CHANGES	2007-11-16 16:31:48 UTC (rev 6666)
@@ -64,6 +64,10 @@
     - Fixed Bug#30892 setObject(int, Object, int, int) delegate in
       PreparedStatmentWrapper delegates to wrong method.
       
+    - Fixed an issue where PreparedStatement.setObject(int, Object, int)
+      didn't handle String values of "1" or "0" for the target SQL type
+      of BIT properly.
+      
 07-19-07 - Version 5.0.7
 
     - Setting the configuration parameter "useCursorFetch" to "true" for 

Modified: branches/branch_5_0/src/com/mysql/jdbc/PreparedStatement.java
===================================================================
--- branches/branch_5_0/src/com/mysql/jdbc/PreparedStatement.java	2007-11-16 15:33:46 UTC (rev 6665)
+++ branches/branch_5_0/src/com/mysql/jdbc/PreparedStatement.java	2007-11-16 16:31:48 UTC (rev 6666)
@@ -2896,11 +2896,16 @@
 		} else if (parameterObj instanceof String) {
 			switch (targetSqlType) {
 			case Types.BIT:
-				boolean parameterAsBoolean = "true"
-						.equalsIgnoreCase((String) parameterObj);
+				if ("1".equals((String) parameterObj)
+						|| "0".equals((String) parameterObj)) {
+					parameterAsNum = Integer.valueOf((String) parameterObj);
+				} else {
+					boolean parameterAsBoolean = "true"
+							.equalsIgnoreCase((String) parameterObj);
 
-				parameterAsNum = parameterAsBoolean ? new Integer(1)
-						: new Integer(0);
+					parameterAsNum = parameterAsBoolean ? new Integer(1)
+							: new Integer(0);
+				}
 
 				break;
 

Modified: branches/branch_5_0/src/testsuite/regression/StatementRegressionTest.java
===================================================================
--- branches/branch_5_0/src/testsuite/regression/StatementRegressionTest.java	2007-11-16 15:33:46 UTC (rev 6665)
+++ branches/branch_5_0/src/testsuite/regression/StatementRegressionTest.java	2007-11-16 16:31:48 UTC (rev 6666)
@@ -4220,4 +4220,83 @@
 			closeMemberJDBCResources();
 		}
 	}
+	
+	public void testLancesBitMappingBug() throws Exception {
+		if (!versionMeetsMinimum(5, 0)) {
+			return;
+		}
+		
+		 createTable("Bit_TabXXX", "( `MAX_VAL` BIT default NULL, "
+				 + "`MIN_VAL` BIT default NULL, `NULL_VAL` BIT default NULL) "
+         		 + "ENGINE=InnoDB DEFAULT CHARSET=latin1");
+         
+         
+         // add Bit_In_MinXXX procedure
+         createProcedure("Bit_In_MinXXX", "(MIN_PARAM TINYINT(1)) begin update Bit_TabXXX set MIN_VAL=MIN_PARAM; end");
+         
+         createProcedure("Bit_In_MaxXXX", "(MAX_PARAM TINYINT(1)) begin update Bit_TabXXX set MAX_VAL=MAX_PARAM; end");
+
+         this.stmt.execute("insert into Bit_TabXXX values(null,0,null)");
+        
+         
+         String sPrepStmt = "{call Bit_In_MinXXX(?)}";
+        this.pstmt = conn.prepareStatement(sPrepStmt);
+        this.pstmt.setObject(1,"true",java.sql.Types.BIT);
+        this.pstmt.executeUpdate();
+        assertEquals("true", getSingleIndexedValueWithQuery(1, "SELECT MIN_VAL FROM Bit_TabXXX").toString());
+        this.stmt.execute("TRUNCATE TABLE Bit_TabXXX");
+        this.stmt.execute("insert into Bit_TabXXX values(null,0,null)");
+        
+        this.pstmt.setObject(1,"false",java.sql.Types.BIT);
+        this.pstmt.executeUpdate();
+        assertEquals("false", getSingleIndexedValueWithQuery(1, "SELECT MIN_VAL FROM Bit_TabXXX").toString());
+        this.stmt.execute("TRUNCATE TABLE Bit_TabXXX");
+        this.stmt.execute("insert into Bit_TabXXX values(null,0,null)");
+        
+        this.pstmt.setObject(1,"1",java.sql.Types.BIT); // fails
+        this.pstmt.executeUpdate();
+        assertEquals("true", getSingleIndexedValueWithQuery(1, "SELECT MIN_VAL FROM Bit_TabXXX").toString());
+        this.stmt.execute("TRUNCATE TABLE Bit_TabXXX");
+        this.stmt.execute("insert into Bit_TabXXX values(null,0,null)");
+        
+        this.pstmt.setObject(1,"0",java.sql.Types.BIT);
+        this.pstmt.executeUpdate();
+        assertEquals("false", getSingleIndexedValueWithQuery(1, "SELECT MIN_VAL FROM Bit_TabXXX").toString());
+        this.stmt.execute("TRUNCATE TABLE Bit_TabXXX");
+        this.stmt.execute("insert into Bit_TabXXX values(null,0,null)");
+         
+        this.pstmt.setObject(1,Boolean.TRUE,java.sql.Types.BIT);
+        this.pstmt.executeUpdate();
+        assertEquals("true", getSingleIndexedValueWithQuery(1, "SELECT MIN_VAL FROM Bit_TabXXX").toString());
+        this.stmt.execute("TRUNCATE TABLE Bit_TabXXX");
+        this.stmt.execute("insert into Bit_TabXXX values(null,0,null)");
+         
+        this.pstmt.setObject(1,Boolean.FALSE,java.sql.Types.BIT);
+        this.pstmt.executeUpdate();
+        assertEquals("false", getSingleIndexedValueWithQuery(1, "SELECT MIN_VAL FROM Bit_TabXXX").toString());
+        this.stmt.execute("TRUNCATE TABLE Bit_TabXXX");
+        this.stmt.execute("insert into Bit_TabXXX values(null,0,null)");
+
+        this.pstmt.setObject(1,new Boolean(true),java.sql.Types.BIT);
+        this.pstmt.executeUpdate();
+        assertEquals("true", getSingleIndexedValueWithQuery(1, "SELECT MIN_VAL FROM Bit_TabXXX").toString());
+        this.stmt.execute("TRUNCATE TABLE Bit_TabXXX");
+        this.stmt.execute("insert into Bit_TabXXX values(null,0,null)");
+         
+        this.pstmt.setObject(1,new Boolean(false),java.sql.Types.BIT);
+        this.pstmt.executeUpdate();
+        assertEquals("false", getSingleIndexedValueWithQuery(1, "SELECT MIN_VAL FROM Bit_TabXXX").toString());
+        this.stmt.execute("TRUNCATE TABLE Bit_TabXXX");
+        this.stmt.execute("insert into Bit_TabXXX values(null,0,null)");
+         
+        this.pstmt.setObject(1,new Byte("1"),java.sql.Types.BIT);
+        this.pstmt.executeUpdate();
+        assertEquals("true", getSingleIndexedValueWithQuery(1, "SELECT MIN_VAL FROM Bit_TabXXX").toString());
+        this.stmt.execute("TRUNCATE TABLE Bit_TabXXX");
+        this.stmt.execute("insert into Bit_TabXXX values(null,0,null)");
+
+        this.pstmt.setObject(1,new Byte("0"),java.sql.Types.BIT);
+        this.pstmt.executeUpdate();
+        assertEquals("false", getSingleIndexedValueWithQuery(1, "SELECT MIN_VAL FROM Bit_TabXXX").toString());
+	}
 }
\ No newline at end of file

Thread
Connector/J commit: r6666 - in branches/branch_5_0: . src/com/mysql/jdbc src/testsuite/regressionmmatthews16 Nov