db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r768940 - in /db/derby/code/branches/10.4/java: engine/org/apache/derby/impl/jdbc/EmbedClob.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
Date Mon, 27 Apr 2009 11:56:09 GMT
Author: kristwaa
Date: Mon Apr 27 11:56:09 2009
New Revision: 768940

URL: http://svn.apache.org/viewvc?rev=768940&view=rev
Log:
DERBY-3991: Clob.truncate(0) throws exception.

Merged fix from trunk (764800).

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

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java?rev=768940&r1=768939&r2=768940&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java (original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java Mon
Apr 27 11:56:09 2009
@@ -620,15 +620,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/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java?rev=768940&r1=768939&r2=768940&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
Mon Apr 27 11:56:09 2009
@@ -304,6 +304,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