From: Date: August 31 2007 2:50am Subject: Connector/J commit: r6540 - in branches/branch_5_0/connector-j: . src/com/mysql/jdbc src/testsuite/regression List-Archive: http://lists.mysql.com/commits/33493 X-Bug: 27867 Message-Id: <200708310050.l7V0od4o011703@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/branch_5_0/connector-j/CHANGES branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java branches/branch_5_0/connector-j/src/testsuite/regression/MetaDataRegressionTest.java Log: Fixed BUG#27867 - Schema objects with identifiers other than the connection character aren't retrieved correctly in ResultSetMetadata. Modified: branches/branch_5_0/connector-j/CHANGES =================================================================== --- branches/branch_5_0/connector-j/CHANGES 2007-08-30 21:49:56 UTC (rev 6539) +++ branches/branch_5_0/connector-j/CHANGES 2007-08-31 00:50:39 UTC (rev 6540) @@ -33,7 +33,11 @@ - Fixed BUG#29852 - Closing a load-balanced connection would cause a ClassCastException. - + + - Fixed BUG#27867 - Schema objects with identifiers other than + the connection character aren't retrieved correctly in + ResultSetMetadata. + 07-19-07 - Version 5.0.7 - Setting the configuration parameter "useCursorFetch" to "true" for Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java =================================================================== --- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java 2007-08-30 21:49:56 UTC (rev 6539) +++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java 2007-08-31 00:50:39 UTC (rev 6540) @@ -86,6 +86,8 @@ */ public class Connection extends ConnectionProperties implements java.sql.Connection { + private static final String JDBC_LOCAL_CHARACTER_SET_RESULTS = "jdbc.local.character_set_results"; + /** * Used as a key for caching callable statements which (may) depend on * current catalog...In 5.0.x, they don't (currently), but stored procedure @@ -2502,20 +2504,36 @@ // the database, so tell the server not to do conversion // if the user hasn't 'forced' a result-set character set // - + + String onServer = null; + boolean isNullOnServer = false; + + if (this.serverVariables != null) { + onServer = (String)this.serverVariables.get("character_set_results"); + + isNullOnServer = onServer == null || "NULL".equalsIgnoreCase(onServer) || onServer.length() == 0; + } + if (getCharacterSetResults() == null) { // - // Only send if needed + // Only send if needed, if we're caching server variables + // we -have- to send, because we don't know what it was + // before we cached them. // - - if (this.serverVariables.get("character_set_results") != null) { - + if (!isNullOnServer) { execSQL(null, "SET character_set_results = NULL", -1, null, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY, false, this.database, true, false); + if (!this.usingCachedConfig) { + this.serverVariables.put(JDBC_LOCAL_CHARACTER_SET_RESULTS, null); + } + } else { + if (!this.usingCachedConfig) { + this.serverVariables.put(JDBC_LOCAL_CHARACTER_SET_RESULTS, onServer); + } } } else { String charsetResults = getCharacterSetResults(); @@ -2541,11 +2559,20 @@ + mysqlEncodingName.length()); setBuf.append("SET character_set_results = ").append( mysqlEncodingName); - + execSQL(null, setBuf.toString(), -1, null, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY, false, this.database, true, false); + + if (!this.usingCachedConfig) { + this.serverVariables.put(JDBC_LOCAL_CHARACTER_SET_RESULTS, + mysqlEncodingName); + } + } else { + if (!this.usingCachedConfig) { + this.serverVariables.put(JDBC_LOCAL_CHARACTER_SET_RESULTS, onServer); + } } } @@ -4139,13 +4166,17 @@ // out what character set metadata will be returned in, // and then map that to a Java encoding name. // + // We've already set it, and it might be different than what + // was originally on the server, which is why we use the + // "special" key to retrieve it if (this.io.versionMeetsMinimum(4, 1, 0)) { String characterSetResultsOnServerMysql = (String) this.serverVariables - .get("character_set_results"); + .get(JDBC_LOCAL_CHARACTER_SET_RESULTS); if (characterSetResultsOnServerMysql == null || StringUtils.startsWithIgnoreCaseAndWs( - characterSetResultsOnServerMysql, "NULL")) { + characterSetResultsOnServerMysql, "NULL") + || characterSetResultsOnServerMysql.length() == 0) { String defaultMetadataCharsetMysql = (String) this.serverVariables .get("character_set_system"); String defaultMetadataCharset = null; @@ -4400,6 +4431,8 @@ return this.isServerTzUTC; } + private boolean usingCachedConfig = false; + /** * Loads the result of 'SHOW VARIABLES' into the serverVariables field so * that the driver can configure itself. @@ -4415,7 +4448,8 @@ if (cachedVariableMap != null) { this.serverVariables = cachedVariableMap; - + this.usingCachedConfig = true; + return; } } @@ -4429,7 +4463,7 @@ stmt.setEscapeProcessing(false); results = (com.mysql.jdbc.ResultSet) stmt - .executeQuery("SHOW VARIABLES"); + .executeQuery("SHOW SESSION VARIABLES"); while (results.next()) { this.serverVariables.put(results.getString(1), results Modified: branches/branch_5_0/connector-j/src/testsuite/regression/MetaDataRegressionTest.java =================================================================== --- branches/branch_5_0/connector-j/src/testsuite/regression/MetaDataRegressionTest.java 2007-08-30 21:49:56 UTC (rev 6539) +++ branches/branch_5_0/connector-j/src/testsuite/regression/MetaDataRegressionTest.java 2007-08-31 00:50:39 UTC (rev 6540) @@ -1951,4 +1951,29 @@ this.conn.prepareCall("{call testBug25624(?,?)}").close(); } + + /** + * Tests fix for BUG#27867 - Schema objects with identifiers other than + * the connection character aren't retrieved correctly in ResultSetMetadata. + * + * @throws Exception if the test fails. + */ + public void testBug27867() throws Exception { + try { + String gbkColumnName = "\u00e4\u00b8\u00ad\u00e6\u2013\u2021\u00e6\u00b5\u2039\u00e8\u00af\u2022"; + createTable("ColumnNameEncoding", "(" + "`" + gbkColumnName + + "` varchar(1) default NULL," + + "`ASCIIColumn` varchar(1) default NULL" + + ")ENGINE=MyISAM DEFAULT CHARSET=utf8"); + + this.rs = this.stmt + .executeQuery("SELECT * FROM ColumnNameEncoding"); + java.sql.ResultSetMetaData tblMD = this.rs.getMetaData(); + + assertEquals(gbkColumnName, tblMD.getColumnName(1)); + assertEquals("ASCIIColumn", tblMD.getColumnName(2)); + } finally { + closeMemberJDBCResources(); + } + } }