You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by kr...@apache.org on 2009/04/27 13:55:18 UTC
svn commit: r768939 - in /db/derby/code/branches/10.5/java:
engine/org/apache/derby/impl/jdbc/EmbedClob.java
testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
Author: kristwaa
Date: Mon Apr 27 11:55:17 2009
New Revision: 768939
URL: http://svn.apache.org/viewvc?rev=768939&view=rev
Log:
DERBY-3991: Clob.truncate(0) throws exception.
Merged fix from trunk (764800).
Modified:
db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java?rev=768939&r1=768938&r2=768939&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java Mon Apr 27 11:55:17 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/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java?rev=768939&r1=768938&r2=768939&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java Mon Apr 27 11:55:17 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()