Bug #4069 strings silently truncated to 65535 bytes
Submitted: 9 Jun 2004 3:36 Modified: 9 Jun 2004 4:12
Reporter: larry h. Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:all tested OS:Solaris (solaris, windows)
Assigned to: CPU Architecture:Any

[9 Jun 2004 3:36] larry h.
Description:
enclosed test class shows mysql java connector problem w/ 65535 limit on string length in prepared statements when using Connector/J;

see line 65 in com.mysql.jdbc.MysqlIO where this limit is apparently set:
private static int maxBufferSize = 65535;

output of this program is
Retrieved string of length: 65535 and expected: 80000

tested using mysql server v. 3.23 & v4.0, using mysql driver v. 3.1.1 alpha & v. 3.0.12 production
 

How to repeat:
see enclosed java program which will duplicate.

see javadoc of file for how to set up test DB.

basically, set a prepared statement for a 'text' field to accommodate a param string, and supply a string > 65535 chars in length.  after setting, retrieve value, and compare lengths.

Suggested fix:
eliminate limit, or throw exception explaining limit was exceeded.  do NOT silently truncate
[9 Jun 2004 3:37] larry h.
java code which reproduces silent truncation

Attachment: MysqlConnTest.java (application/octet-stream, text), 3.84 KiB.

[9 Jun 2004 4:12] Mark Matthews
The TEXT datatype that you use in your example only holds 65536 characters (see http://dev.mysql.com/doc/mysql/en/String_type_overview.html), if you actually want to hold longer strings, you should use MEDIUMTEXT or LONGTEXT.

Truncation warnings are only available when the server supports them, and that's not until server version 4.1.2 (basically this is a dupe of BUG#3804, which has been fixed and closed for MySQL Connector/J 3.1.2 which was released earlier today).
[9 Jun 2004 4:16] larry h.
Thanks, that helps.  So the driver can't get warn if it knows, separately, that text is too long for the type?