db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r764800 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/EmbedClob.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
Date Tue, 14 Apr 2009 14:46:44 GMT
Author: kristwaa
Date: Tue Apr 14 14:46:43 2009
New Revision: 764800

URL: http://svn.apache.org/viewvc?rev=764800&view=rev
Log:
DERBY-3991: Clob.truncate(0) throws exception.
Allows a Clob to be truncated to a length of zero characters (empty string).

Patch contributed by Yun Lee <yun.lee.bj@gmail.com>.

Patch file: derby-3991-3.diff


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java?rev=764800&r1=764799&r2=764800&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java Tue Apr 14 14:46:43
2009
@@ -616,15 +616,15 @@
      * len characters
      *
      * @param len the length, in characters, to which the CLOB value should be
-     *      truncated
+     *      truncated, 0 is accepted
      * @exception SQLException if truncating the CLOB value fails
      */
     public void truncate(long len) throws SQLException
     {
         checkValidity();
-        if (len < 1)
+        if (len < 0)
             throw Util.generateCsSQLException(
-                SQLState.BLOB_BAD_POSITION, new Long(len));
+                SQLState.BLOB_NONPOSITIVE_LENGTH, new Long(len));
         try {
             if (!clob.isWritable()) {
                 makeWritableClobClone(len);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java?rev=764800&r1=764799&r2=764800&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
Tue Apr 14 14:46:43 2009
@@ -387,6 +387,42 @@
     }
 
     /**
+     * Truncating a Clob to the empty string.
+     */
+    public void testTruncateZeroOnDisk()
+            throws IOException, SQLException {
+        long size = 33*1024+7;
+        insertDataWithToken("", size, 0, SET_CHARACTER_STREAM);
+        truncateToZero(size);
+    }
+
+    /**
+     * Truncating a Clob to the empty string.
+     */
+    public void testTruncateZeroInMemory()
+            throws IOException, SQLException {
+        long size = 33;
+        insertDataWithToken("", size, 0, SET_STRING);
+        truncateToZero(size);
+    }
+
+    /**
+     * Truncates the default Clob to zero length and checks some basic
+     * operations on the empty Clob.
+     *
+     * @param initSize the expected size of the Clob to truncate
+     */
+    private void truncateToZero(long initSize)
+            throws IOException, SQLException {
+        assertEquals(initSize, this.clob.length());
+        this.clob.truncate(0);
+        assertEquals(0L, this.clob.length());
+        assertEquals("", this.clob.getSubString(1, 0));
+        assertEquals("", this.clob.getSubString(1, 1));
+        assertEquals(-1, this.clob.getCharacterStream().read());
+    }
+
+    /**
      * Truncating a Clob to the current length should work.
      */
     public void testTruncateExactOnDisk()



Mime
View raw message