MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:mmatthews Date:October 23 2007 5:47pm
Subject:Connector/J commit: r6643 - in branches/branch_5_1: . src/com/mysql/jdbc
View as plain text  
Modified:
   branches/branch_5_1/CHANGES
   branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java
   branches/branch_5_1/src/com/mysql/jdbc/DatabaseMetaData.java
   branches/branch_5_1/src/com/mysql/jdbc/Field.java
Log:
Fixed Bug#20491 - DatabaseMetadata.getColumns() doesn't
      return correct column names if connection character set
      isn't UTF-8. (There was a server-side component of this that
      was fixed late in the 5.0 development cycle, it seems, this
      is the last piece that fixes some loose ends in the JDBC
      driver). This fix touches *all* metadata information coming
      from the MySQL server itself.

Modified: branches/branch_5_1/CHANGES
===================================================================
--- branches/branch_5_1/CHANGES	2007-10-23 16:17:14 UTC (rev 6642)
+++ branches/branch_5_1/CHANGES	2007-10-23 17:47:15 UTC (rev 6643)
@@ -7,6 +7,14 @@
     - Fixed BUG#31790 MysqlValidConnectionChecker 
       doesn't properly handle ReplicationConnection
     
+    - Fixed Bug#20491 - DatabaseMetadata.getColumns() doesn't
+      return correct column names if connection character set
+      isn't UTF-8. (There was a server-side component of this that
+      was fixed late in the 5.0 development cycle, it seems, this
+      is the last piece that fixes some loose ends in the JDBC
+      driver). This fix touches *all* metadata information coming
+      from the MySQL server itself.
+      
 10-09-07 - Version 5.1.5
 
     - Released instead of 5.1.4 to pickup patch for BUG#31053

Modified: branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java	2007-10-23 16:17:14 UTC (rev 6642)
+++ branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java	2007-10-23 17:47:15 UTC (rev 6643)
@@ -2728,7 +2728,7 @@
 	 * @return Returns the characterSetMetadata.
 	 */
 	protected String getCharacterSetMetadata() {
-		return characterSetMetadata;
+		return this.characterSetMetadata;
 	}
 
 	/**
@@ -3479,6 +3479,8 @@
 								characterSetResultsOnServerMysql, this);
 				this.characterSetMetadata = this.characterSetResultsOnServer;
 			}
+		} else {
+			this.characterSetMetadata = getEncoding();
 		}
 
 		//

Modified: branches/branch_5_1/src/com/mysql/jdbc/DatabaseMetaData.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/DatabaseMetaData.java	2007-10-23 16:17:14 UTC (rev 6642)
+++ branches/branch_5_1/src/com/mysql/jdbc/DatabaseMetaData.java	2007-10-23 17:47:15 UTC (rev 6643)
@@ -700,6 +700,18 @@
 		int fieldsLength = fields.length;
 
 		for (int i = 0; i < fieldsLength; i++) {
+			int jdbcType = fields[i].getSQLType();
+			
+			switch (jdbcType) {
+			case Types.CHAR:
+			case Types.VARCHAR:
+			case Types.LONGVARCHAR:
+				fields[i].setCharacterSet(c.getCharacterSetMetadata());
+				break;
+			default:
+				// do nothing
+			}
+			
 			fields[i].setConnection(c);
 			fields[i].setUseOldNameMetadata(true);
 		}
@@ -6940,9 +6952,14 @@
 	 * @return DOCUMENT ME!
 	 */
 	protected byte[] s2b(String s) throws SQLException {
-		return StringUtils.s2b(s, this.conn);
+		if (s == null) {
+			return null;
+		}
+		
+		return StringUtils.getBytes(s, this.conn.getCharacterSetMetadata(),
+				this.conn.getServerCharacterEncoding(), this.conn
+						.parserKnowsUnicode(), this.conn);
 	}
-	
 
 	/**
 	 * Does the database store mixed case unquoted SQL identifiers in lower

Modified: branches/branch_5_1/src/com/mysql/jdbc/Field.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/Field.java	2007-10-23 16:17:14 UTC (rev 6642)
+++ branches/branch_5_1/src/com/mysql/jdbc/Field.java	2007-10-23 17:47:15 UTC (rev 6643)
@@ -416,6 +416,12 @@
 		return this.charsetName;
 	}
 
+	public void setCharacterSet(String javaEncodingName) throws SQLException {
+		this.charsetName = javaEncodingName;
+		this.charsetIndex = CharsetMapping
+				.getCharsetIndexForMysqlEncodingName(javaEncodingName);
+	}
+	
 	public synchronized String getCollation() throws SQLException {
 		if (this.collationName == null) {
 			if (this.connection != null) {
@@ -938,7 +944,9 @@
 	public void setConnection(ConnectionImpl conn) {
 		this.connection = conn;
 
-		this.charsetName = this.connection.getEncoding();
+		if (this.charsetName == null || this.charsetIndex == 0) {
+			this.charsetName = this.connection.getEncoding();
+		}
 	}
 
 	void setMysqlType(int type) {

Thread
Connector/J commit: r6643 - in branches/branch_5_1: . src/com/mysql/jdbcmmatthews23 Oct