db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r678769 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/types/SQLBinary.java testing/org/apache/derbyTesting/functionTests/tests/memory/BlobMemTest.java
Date Tue, 22 Jul 2008 14:19:13 GMT
Author: bpendleton
Date: Tue Jul 22 07:19:13 2008
New Revision: 678769

URL: http://svn.apache.org/viewvc?rev=678769&view=rev
Log:
DERBY-961: Error 22001 can include 'XX-RESOLVE-XX' which should be removed

In some cases, error 22001 can come up as follows:

   A truncation error was encountered trying to shrink
   CHAR () FOR BIT DATA 'XX-RESOLVE-XX' to length 40.

This message makes it appear as if there is a column called XX-RESOLVE-XX,
however, this string is hard-coded in SQLBinary.java, and should be removed.

The intent of the XX-RESOLVE-XX message parameter is to hold the actual
value which could not be shrunk to fit in the column. For a SQLBinary
data type, the actual value may not be human-readable, and so cannot
be displayed.

This patch changes the XX-RESOLVE-XX parameter to the message to
"(Binary data value not displayed)", which should give a better hint to
the person who received this error message about what was going on. 

The patch also adds a new test case to BlobMemTest to force the code to
emit the 22001 message from SQLBinary, to ensure that this code path
is run in our tests.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBinary.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/BlobMemTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBinary.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBinary.java?rev=678769&r1=678768&r2=678769&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBinary.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBinary.java Tue Jul 22
07:19:13 2008
@@ -1053,7 +1053,7 @@
 
 		if (variableLength != -1 && variableLength > declaredLength)
 				throw StandardException.newException(SQLState.LANG_STRING_TRUNCATION, getTypeName(),

-							"XX-RESOLVE-XX",
+							"(Binary data value not displayed)",
 							String.valueOf(declaredLength));
 	}
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/BlobMemTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/BlobMemTest.java?rev=678769&r1=678768&r2=678769&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/BlobMemTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/BlobMemTest.java
Tue Jul 22 07:19:13 2008
@@ -71,7 +71,7 @@
      * @throws IllegalAccessException 
      * @throws IllegalArgumentException 
      */
-    private void testBlobLength(boolean lengthless) throws SQLException, IOException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
+    private void testBlobLength(boolean lengthless, int extraLen) throws SQLException, IOException,
IllegalArgumentException, IllegalAccessException, InvocationTargetException {
         setAutoCommit(false);
         Statement s = createStatement();
         s.executeUpdate("CREATE TABLE BLOBTAB (K INT CONSTRAINT PK PRIMARY KEY, B BLOB("
+ LONG_BLOB_LENGTH + "))");
@@ -79,7 +79,8 @@
         PreparedStatement ps = prepareStatement("INSERT INTO BLOBTAB VALUES(?,?)");
         // We allocate 16MB for the test so use something bigger than that.
         ps.setInt(1,1);
-        LoopingAlphabetStream stream = new LoopingAlphabetStream(LONG_BLOB_LENGTH);
+        int blobLen = LONG_BLOB_LENGTH + extraLen;
+        LoopingAlphabetStream stream = new LoopingAlphabetStream(blobLen);
         if (lengthless) {
             Method m = null;
             try {
@@ -95,8 +96,26 @@
             m.invoke(ps, new Object[] {new Integer(2),stream});
         }
         else
-            ps.setBinaryStream(2, stream,LONG_BLOB_LENGTH);
-        ps.executeUpdate();
+            ps.setBinaryStream(2, stream,blobLen);
+        if (extraLen == 0)
+        {
+            ps.executeUpdate();
+        }
+        else
+        {
+            try
+            {
+                ps.executeUpdate();
+                fail("Expected truncation error for blob too large");
+            }
+            catch (SQLException sqlE)
+            {
+                assertSQLState("Wrong SQL State for truncation", "22001", sqlE);
+            }
+            // extraLen > 0 is just a way to force the truncation error. Once
+            // we've forced that error, we're done testing, so return.
+            return;
+        }
         // insert a zero length blob.
         ps.setInt(1, 2);
         ps.setBytes(2, new byte[] {});
@@ -168,7 +187,7 @@
      * @throws IllegalArgumentException 
      */
     public void testBlobLength() throws SQLException, IOException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
-        testBlobLength(false);
+        testBlobLength(false, 0);
     }
     
     /**
@@ -183,7 +202,13 @@
      * @throws IllegalArgumentException 
      */
     public void testBlobLengthWithLengthlessInsert() throws SQLException, IOException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException {        
-        testBlobLength(true);  
+        testBlobLength(true, 0);  
+    }
+    /**
+      * Simple test to excercise message 22001 as described in DERBY-961.
+      */
+    public void testBlobLengthTooLongDerby961() throws SQLException, IOException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException {        
+        testBlobLength(false, 10000);  
     }
        public static Test suite() {
         Test suite =  TestConfiguration.defaultSuite(BlobMemTest.class);



Mime
View raw message