Bug #21544 Connector/J does not consider property jdbcCompliantTruncation
Submitted: 9 Aug 2006 15:59 Modified: 15 Aug 2006 14:32
Reporter: Hakan Küçükyılmaz Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.0.3 OS:
Assigned to: Mark Matthews CPU Architecture:Any
Tags: Starting from SVN 5403

[9 Aug 2006 15:59] Hakan Küçükyılmaz
Description:
Setting jdbcCompliantTruncation=false has no effect.

How to repeat:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class MetaDataLongTextSize {
	public static final String TABLE_NAME = "foo";

    // public static final String URL =
    // "jdbc:mysql:///test?user=root&password=X&jdbcCompliantTruncation=true";
    public static final String URL = "jdbc:mysql:///test?user=root&password=supersecret&useInformationSchema=true&jdbcCompliantTruncation=false";

    private Connection conn;

    protected void setUp() throws SQLException {
        new com.mysql.jdbc.Driver();
        conn = DriverManager.getConnection(URL);
    }

    public void testMetaDataLongTextSize() throws SQLException {
        createTable();

        ResultSet rs = conn.getMetaData().getColumns(null, null, TABLE_NAME,
                null);
        try {
            System.out.println("Integer.MAX_VALUE = " + Integer.MAX_VALUE);
            while (rs.next()) {
                long colSize = rs.getLong("COLUMN_SIZE");
                try {
                    System.out.println(rs.getString("COLUMN_NAME") + " "
                            + rs.getInt("COLUMN_SIZE"));
                } catch (Exception e) {
                    if (colSize > Integer.MAX_VALUE) {
                        String msg = "Sorry: " + colSize + " > "
                                + Integer.MAX_VALUE;
                        throw new RuntimeException(msg, e);
                    }
                }
            }
        } finally {
            rs.close();
        }
    }

    private void createTable() throws SQLException {
        Statement stmt = conn.createStatement();
        try {
            stmt.executeUpdate("DROP TABLE IF EXISTS " + TABLE_NAME);
            stmt.executeUpdate("CREATE TABLE " + TABLE_NAME
                    + "(foo_id INT NOT NULL, stuff LONGTEXT"
                    + ", PRIMARY KEY (foo_id)) TYPE=INNODB");
        } finally {
            stmt.close();
        }
    }

    protected void tearDown() {
        if (conn != null) {
            try {
                Statement stmt = conn.createStatement();
                stmt.executeUpdate("DROP TABLE IF EXISTS " + TABLE_NAME);
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                conn.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws Exception {
        MetaDataLongTextSize instance = new MetaDataLongTextSize();
        try {
            instance.setUp();
            instance.testMetaDataLongTextSize();
        } finally {
            instance.tearDown();
        }
    }
}

Suggested fix:
In ConnectionProperties.java jdbcCompliantTruncationForReads is introduced but not initialized properly (only the default value for jdbcCompliantTruncation, which is true, is used).

Fix:
Set jdbcCompliantTruncationForReads in ConnectionProperties::postInitialization().
Around line 2633 add:
...
...
...
this.maintainTimeStatsAsBoolean = this.maintainTimeStats
	.getValueAsBoolean();
this.jdbcCompliantTruncationForReads =
	this.jdbcCompliantTruncation.getValueAsBoolean();
...

Regards, Hakan
[15 Aug 2006 14:30] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/10481
[13 Sep 2006 14:43] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/11855