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