Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BE26379B0 for ; Sat, 10 Sep 2011 07:01:21 +0000 (UTC) Received: (qmail 10001 invoked by uid 500); 10 Sep 2011 07:01:20 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 9923 invoked by uid 500); 10 Sep 2011 07:01:05 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 9899 invoked by uid 99); 10 Sep 2011 07:01:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 10 Sep 2011 07:01:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 10 Sep 2011 07:01:00 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 635512388AA9; Sat, 10 Sep 2011 07:00:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1167470 - in /db/derby/code/trunk/java/drda/org/apache/derby/impl/drda: AppRequester.java DDMWriter.java Date: Sat, 10 Sep 2011 07:00:39 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110910070039.635512388AA9@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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,