From: Date: August 31 2007 3:22am Subject: Connector/J commit: r6543 - in branches/branch_5_1: . connector-j connector-j/src/com/mysql/jdbc connector-j/src/testsuite/regression List-Archive: http://lists.mysql.com/commits/33496 X-Bug: 27867 Message-Id: <200708310122.l7V1MpAq022956@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/branch_5_1/ branches/branch_5_1/connector-j/CHANGES branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionImpl.java branches/branch_5_1/connector-j/src/testsuite/regression/MetaDataRegressionTest.java Log: Merged revisions 6398-6402,6405-6407,6414-6473,6475,6477,6480,6483-6486,6489-6492,6496-6500,6509-6511,6513,6517-6518,6521-6522,6524,6526-6528,6530-6531,6533-6534,6536-6537,6539-6542 via svnmerge from svn+ssh://mmatthews@stripped/connectors-svnroot/connector-j/trunk ............... r6541 | mmatthews | 2007-08-30 20:15:59 -0500 (Thu, 30 Aug 2007) | 13 lines Merged revisions 6538-6540 via svnmerge from svn+ssh://mmatthews@stripped/connectors-svnroot/connector-j/branches/branch_5_0 ........ r6540 | mmatthews | 2007-08-30 19:50:39 -0500 (Thu, 30 Aug 2007) | 3 lines Fixed BUG#27867 - Schema objects with identifiers other than the connection character aren't retrieved correctly in ResultSetMetadata. ........ ............... r6542 | mmatthews | 2007-08-30 20:17:04 -0500 (Thu, 30 Aug 2007) | 1 line Post-merge fixups. ............... Property changes on: branches/branch_5_1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-6396,6398-6402,6405-6407,6414-6473,6475,6477,6480,6483-6486,6489-6492,6496-6500,6509-6511,6513,6517-6518,6521-6538 + /trunk:1-6396,6398-6402,6405-6407,6414-6473,6475,6477,6480,6483-6486,6489-6492,6496-6500,6509-6511,6513,6517-6518,6521-6542 Modified: branches/branch_5_1/connector-j/CHANGES =================================================================== --- branches/branch_5_1/connector-j/CHANGES 2007-08-31 01:17:04 UTC (rev 6542) +++ branches/branch_5_1/connector-j/CHANGES 2007-08-31 01:22:50 UTC (rev 6543) @@ -211,7 +211,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_1/connector-j/src/com/mysql/jdbc/ConnectionImpl.java =================================================================== --- branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionImpl.java 2007-08-31 01:17:04 UTC (rev 6542) +++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionImpl.java 2007-08-31 01:22:50 UTC (rev 6543) @@ -72,6 +72,8 @@ */ public class ConnectionImpl extends ConnectionPropertiesImpl implements 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 @@ -1732,19 +1734,35 @@ // 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, null, 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(); @@ -1775,6 +1793,15 @@ java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY, false, this.database, null, 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); + } } } @@ -3363,13 +3390,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; @@ -3589,6 +3620,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. @@ -3604,6 +3637,7 @@ if (cachedVariableMap != null) { this.serverVariables = cachedVariableMap; + this.usingCachedConfig = true; return; } Modified: branches/branch_5_1/connector-j/src/testsuite/regression/MetaDataRegressionTest.java =================================================================== --- branches/branch_5_1/connector-j/src/testsuite/regression/MetaDataRegressionTest.java 2007-08-31 01:17:04 UTC (rev 6542) +++ branches/branch_5_1/connector-j/src/testsuite/regression/MetaDataRegressionTest.java 2007-08-31 01:22:50 UTC (rev 6543) @@ -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(); + } + } }