db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1073287 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/types/SQLBoolean.java testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
Date Tue, 22 Feb 2011 10:26:38 GMT
Author: kahatlen
Date: Tue Feb 22 10:26:38 2011
New Revision: 1073287

URL: http://svn.apache.org/viewvc?rev=1073287&view=rev
Log:
DERBY-5063: Embedded driver allows updateBytes() on BOOLEAN column

Make embedded driver throw same exception as the client driver when
updateBytes() is executed on a BOOLEAN column.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBoolean.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBoolean.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBoolean.java?rev=1073287&r1=1073286&r2=1073287&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBoolean.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBoolean.java Tue Feb 22
10:26:38 2011
@@ -520,45 +520,6 @@ public final class SQLBoolean
 	}
 
 	/**
-	 * Set the value of this BooleanDataValue to the given byte array value
-	 *
-	 * @param theValue	The value to set this BooleanDataValue to
-	 */
-	public void setValue(byte[] theValue)
-	{
-		if (SanityManager.DEBUG)
-			SanityManager.ASSERT( ! immutable,
-						"Attempt to set the value of an immutable SQLBoolean");
-
-		if (theValue != null)
-		{
-			isnull = false;
-			int length = theValue.length;
-	
-			/*
-			** Step through all bytes.  As soon
-			** as we get one with something other
-			** than 0, then we know we have a 'true'
-			*/
-			for (int i = 0; i < length; i++)
-			{
-				if (theValue[i] != 0)
-				{
-					value = true;
-					return;
-				}
-			}
-		}
-		else
-		{
-			isnull = true;
-		}
-		value = false;
-
-	}
-
-
-	/**
 	 * Set the value of this BooleanDataValue to the given String.
 	 * String is trimmed and upcased.  If resultant string is not
 	 * TRUE or FALSE, then an error is thrown.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java?rev=1073287&r1=1073286&r2=1073287&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
Tue Feb 22 10:26:38 2011
@@ -58,6 +58,7 @@ public class BooleanValuesTest  extends 
     private static final String BAD_CONVERSION = "42846";
     private static final String ILLEGAL_INSERT = "42821";
     private static final String BAD_DEFAULT = "42894";
+    private static final String ILLEGAL_UPDATE = "XCL12";
 
     ///////////////////////////////////////////////////////////////////////////////////
     //
@@ -1818,6 +1819,44 @@ public class BooleanValuesTest  extends 
         }
     }
 
+    /**
+     * Verify fix for DERBY-5063 - updateBytes() should fail when invoked
+     * on boolean columns.
+     */
+    public void test_5063_updateBytes() throws SQLException {
+        setAutoCommit(false);
+
+        Statement s = createStatement();
+        s.execute("create table derby5063(b boolean)");
+
+        PreparedStatement ps = prepareStatement("select b from derby5063",
+                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+
+        byte[] bytes = "abc".getBytes();
+
+        // Test updateBytes()
+        ResultSet rs = ps.executeQuery();
+        rs.moveToInsertRow();
+        try {
+            rs.updateBytes(1, bytes);
+            fail("updateBytes should fail");
+        } catch (SQLException sqle) {
+            assertSQLState(ILLEGAL_UPDATE, sqle);
+        }
+        rs.close();
+
+        // setObject() should also fail when the argument is a byte array
+        rs = ps.executeQuery();
+        rs.moveToInsertRow();
+        try {
+            rs.updateObject(1, bytes);
+            fail("updateObject should fail");
+        } catch (SQLException sqle) {
+            assertSQLState(ILLEGAL_UPDATE, sqle);
+        }
+        rs.close();
+    }
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // SQL ROUTINES



Mime
View raw message