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 ka...@apache.org on 2011/09/10 09:00:39 UTC

svn commit: r1167470 - in /db/derby/code/trunk/java/drda/org/apache/derby/impl/drda: AppRequester.java DDMWriter.java

Author: kahatlen
Date: Sat Sep 10 07:00:38 2011
New Revision: 1167470

URL: http://svn.apache.org/viewvc?rev=1167470&view=rev
Log:
DERBY-5236: Client driver silently truncates strings that exceed 32KB

Disable the fix when talking to old clients because they may get a
StringIndexOutOfBoundsException if they receive longer strings, and
they also don't know exactly how to handle java.sql.DataTruncation
warnings.

Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java?rev=1167470&r1=1167469&r2=1167470&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java Sat Sep 10 07:00:38 2011
@@ -331,6 +331,16 @@ class AppRequester
 	}
 
     /**
+     * Return true if the client contains the fix for DERBY-5236, which allows
+     * DDMWriter.writeLDString() to write strings that need up to 64K-1 bytes
+     * when represented in UTF-8. Otherwise, writeLDString() should use the
+     * old maximum length, which is 32700 bytes.
+     */
+    protected boolean supportsLongerLDStrings() {
+        return clientType == DNC_CLIENT && greaterThanOrEqualTo(10, 8, 2);
+    }
+
+    /**
      * The timestamp length may be truncated for old versions of Derby.
      * See DERBY-2602.
      */

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java?rev=1167470&r1=1167469&r2=1167470&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java Sat Sep 10 07:00:38 2011
@@ -1245,13 +1245,29 @@ class DDMWriter
         // Write the string.
         writeString(s);
 
+        // Find out how long strings the client supports, and possibly
+        // truncate the string before sending it.
+
+        int maxByteLength = MAX_VARCHAR_BYTE_LENGTH;
+        boolean warnOnTruncation = true;
+
+        AppRequester appRequester = agent.getSession().appRequester;
+        if (appRequester != null && !appRequester.supportsLongerLDStrings()) {
+            // The client suffers from DERBY-5236, and it doesn't support
+            // receiving as long strings as newer clients do. It also doesn't
+            // know exactly what to do with a DataTruncation warning, so skip
+            // sending it to old clients.
+            maxByteLength = FdocaConstants.LONGVARCHAR_MAX_LEN;
+            warnOnTruncation = false;
+        }
+
         int byteLength = buffer.position() - stringPos;
 
         // If the byte representation of the string is too long, it needs to
         // be truncated.
-        if (byteLength > MAX_VARCHAR_BYTE_LENGTH) {
+        if (byteLength > maxByteLength) {
             // Truncate the string down to the maximum byte length.
-            byteLength = MAX_VARCHAR_BYTE_LENGTH;
+            byteLength = maxByteLength;
             // Align with character boundaries so that we don't send over
             // half a character.
             while (isContinuationByte(buffer.get(stringPos + byteLength))) {
@@ -1269,9 +1285,10 @@ class DDMWriter
             // Set the buffer position right after the truncated string.
             buffer.position(stringPos + byteLength);
 
-            // If invoked as part of statement execution, add a warning about
+            // If invoked as part of statement execution, and the client
+            // supports receiving DataTruncation warnings, add a warning about
             // the string being truncated.
-            if (stmt != null) {
+            if (warnOnTruncation && stmt != null) {
                 DataTruncation dt = new DataTruncation(
                         index,
                         isParameter,