Bug #21544 Connector/J does not consider property jdbcCompliantTruncation
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
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.052 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
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