MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:mmatthews Date:October 23 2007 6:01pm
Subject:Connector/J commit: r6649 - in trunk: . src/com/mysql/jdbc src/com/mysql/jdbc/integration/jboss src/testsuite/regression
View as plain text  
Modified:
   trunk/
   trunk/CHANGES
   trunk/src/com/mysql/jdbc/ConnectionImpl.java
   trunk/src/com/mysql/jdbc/DatabaseMetaData.java
   trunk/src/com/mysql/jdbc/Field.java
   trunk/src/com/mysql/jdbc/MysqlIO.java
   trunk/src/com/mysql/jdbc/PreparedStatement.java
   trunk/src/com/mysql/jdbc/ReplicationConnection.java
   trunk/src/com/mysql/jdbc/Util.java
   trunk/src/com/mysql/jdbc/integration/jboss/MysqlValidConnectionChecker.java
   trunk/src/testsuite/regression/MetaDataRegressionTest.java
   trunk/src/testsuite/regression/ResultSetRegressionTest.java
   trunk/src/testsuite/regression/StatementRegressionTest.java
Log:
Merged revisions 6585-6586,6593-6597,6599-6602,6605,6607-6609,6612,6614-6617,6619-6620,6623-6627,6632,6636-6638,6641-6648 via svnmerge from 
svn+ssh://mmatthews@stripped/connectors-svnroot/connector-j/branches/branch_5_1

.......
  r6642 | mmatthews | 2007-10-23 11:17:14 -0500 (Tue, 23 Oct 2007) | 1 line
  
  Fixed BUG#31790 MysqlValidConnectionChecker  doesn't properly handle ReplicationConnection.
.......
  r6643 | mmatthews | 2007-10-23 12:47:15 -0500 (Tue, 23 Oct 2007) | 7 lines
  
  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.
.......
  r6644 | mmatthews | 2007-10-23 12:49:01 -0500 (Tue, 23 Oct 2007) | 3 lines
  
  Fixed MysqlIO.nextRowFast() to only attempt to read server
  
        warning counts and status if talking to a 4.1 or newer server
  
        (fixes a hang when reading data from 4.0 servers).
.......
  r6645 | mmatthews | 2007-10-23 12:51:10 -0500 (Tue, 23 Oct 2007) | 1 line
  
  Testcase for bug 20491.
.......
  r6646 | mmatthews | 2007-10-23 12:52:09 -0500 (Tue, 23 Oct 2007) | 1 line
  
  Make a default constructor so others can extend this class.
.......
  r6647 | mmatthews | 2007-10-23 12:52:39 -0500 (Tue, 23 Oct 2007) | 1 line
  
  Changed some visibility to make things usable from StatementInterceptor implementations.
.......
  r6648 | mmatthews | 2007-10-23 12:55:22 -0500 (Tue, 23 Oct 2007) | 1 line
  
  Don't run these tests on MySQL-4.0.x
.......



Property changes on: trunk
___________________________________________________________________
Name: svnmerge-integrated
   - /branches/branch_5_0:1-6625 /branches/branch_5_1:1-6582,6584-6640
   + /branches/branch_5_0:1-6625 /branches/branch_5_1:1-6582,6584-6648

Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES	2007-10-23 17:55:22 UTC (rev 6648)
+++ trunk/CHANGES	2007-10-23 18:01:29 UTC (rev 6649)
@@ -4,6 +4,21 @@
 
     - JDBC-4.0-ized XAConnections and datasources.
     
+    - 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.
+      
+    - Fixed MysqlIO.nextRowFast() to only attempt to read server
+      warning counts and status if talking to a 4.1 or newer server
+      (fixes a hang when reading data from 4.0 servers).
+      
 10-09-07 - Version 5.1.5
 
     - Released instead of 5.1.4 to pickup patch for BUG#31053

Modified: trunk/src/com/mysql/jdbc/ConnectionImpl.java
===================================================================
--- trunk/src/com/mysql/jdbc/ConnectionImpl.java	2007-10-23 17:55:22 UTC (rev 6648)
+++ trunk/src/com/mysql/jdbc/ConnectionImpl.java	2007-10-23 18:01:29 UTC (rev 6649)
@@ -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: trunk/src/com/mysql/jdbc/DatabaseMetaData.java
===================================================================
--- trunk/src/com/mysql/jdbc/DatabaseMetaData.java	2007-10-23 17:55:22 UTC (rev 6648)
+++ trunk/src/com/mysql/jdbc/DatabaseMetaData.java	2007-10-23 18:01:29 UTC (rev 6649)
@@ -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: trunk/src/com/mysql/jdbc/Field.java
===================================================================
--- trunk/src/com/mysql/jdbc/Field.java	2007-10-23 17:55:22 UTC (rev 6648)
+++ trunk/src/com/mysql/jdbc/Field.java	2007-10-23 18:01:29 UTC (rev 6649)
@@ -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) {

Modified: trunk/src/com/mysql/jdbc/MysqlIO.java
===================================================================
--- trunk/src/com/mysql/jdbc/MysqlIO.java	2007-10-23 17:55:22 UTC (rev 6648)
+++ trunk/src/com/mysql/jdbc/MysqlIO.java	2007-10-23 18:01:29 UTC (rev 6649)
@@ -1518,20 +1518,25 @@
 					}
 
 					if (sw == 254 && packetLength < 9) {
-						this.warningCount = (this.mysqlInput.read() & 0xff)
-						| ((this.mysqlInput.read() & 0xff) << 8);
-						remaining -= 2;
+						if (this.use41Extensions) {
+							this.warningCount = (this.mysqlInput.read() & 0xff)
+									| ((this.mysqlInput.read() & 0xff) << 8);
+							remaining -= 2;
 
-			            if (this.warningCount > 0) {
-			                this.hadWarnings = true; // this is a 'latch', it's reset by sendCommand()
-			            }
+							if (this.warningCount > 0) {
+								this.hadWarnings = true; // this is a
+															// 'latch', it's
+															// reset by
+															// sendCommand()
+							}
 
-			            this.serverStatus = (this.mysqlInput.read() & 0xff)
-						| ((this.mysqlInput.read() & 0xff) << 8);
-						remaining -= 2;
+							this.serverStatus = (this.mysqlInput.read() & 0xff)
+									| ((this.mysqlInput.read() & 0xff) << 8);
+							remaining -= 2;
 
-						if (remaining > 0) {
-							skipFully(this.mysqlInput, remaining);
+							if (remaining > 0) {
+								skipFully(this.mysqlInput, remaining);
+							}
 						}
 
 						return null; // last data packet

Modified: trunk/src/com/mysql/jdbc/PreparedStatement.java
===================================================================
--- trunk/src/com/mysql/jdbc/PreparedStatement.java	2007-10-23 17:55:22 UTC (rev 6648)
+++ trunk/src/com/mysql/jdbc/PreparedStatement.java	2007-10-23 18:01:29 UTC (rev 6649)
@@ -5038,4 +5038,8 @@
 			return this.parameterIsNull[parameterIndex -1];
 		}	
 	}
-}
+	
+	public String getPreparedSql() {
+		return this.originalSql;
+	}
+}
\ No newline at end of file

Modified: trunk/src/com/mysql/jdbc/ReplicationConnection.java
===================================================================
--- trunk/src/com/mysql/jdbc/ReplicationConnection.java	2007-10-23 17:55:22 UTC (rev 6648)
+++ trunk/src/com/mysql/jdbc/ReplicationConnection.java	2007-10-23 18:01:29 UTC (rev 6649)
@@ -50,6 +50,8 @@
 
 	protected Connection slavesConnection;
 
+	protected ReplicationConnection() {}
+	
 	public ReplicationConnection(Properties masterProperties,
 			Properties slaveProperties) throws SQLException {
 		NonRegisteringDriver driver = new NonRegisteringDriver();

Modified: trunk/src/com/mysql/jdbc/Util.java
===================================================================
--- trunk/src/com/mysql/jdbc/Util.java	2007-10-23 17:55:22 UTC (rev 6648)
+++ trunk/src/com/mysql/jdbc/Util.java	2007-10-23 18:01:29 UTC (rev 6649)
@@ -59,7 +59,7 @@
 		}
 	}
 
-	protected static boolean nanoTimeAvailable() {
+	public static boolean nanoTimeAvailable() {
 		return systemNanoTimeMethod != null;
 	}
 
@@ -487,7 +487,7 @@
 
 		return System.currentTimeMillis();
 	}
-
+	
 	public static void resultSetToMap(Map mappedValues, java.sql.ResultSet rs)
 			throws SQLException {
 		while (rs.next()) {

Modified: trunk/src/com/mysql/jdbc/integration/jboss/MysqlValidConnectionChecker.java
===================================================================
--- trunk/src/com/mysql/jdbc/integration/jboss/MysqlValidConnectionChecker.java	2007-10-23 17:55:22 UTC (rev 6648)
+++ trunk/src/com/mysql/jdbc/integration/jboss/MysqlValidConnectionChecker.java	2007-10-23 18:01:29 UTC (rev 6649)
@@ -30,6 +30,7 @@
 
 import org.jboss.resource.adapter.jdbc.ValidConnectionChecker;
 
+import com.mysql.jdbc.PingTarget;
 import com.mysql.jdbc.SQLError;
 
 /**
@@ -74,7 +75,17 @@
 	 * @see org.jboss.resource.adapter.jdbc.ValidConnectionChecker#isValidConnection(java.sql.Connection)
 	 */
 	public SQLException isValidConnection(Connection conn) {
-		if (conn instanceof com.mysql.jdbc.Connection) {
+		if (conn instanceof PingTarget) {
+			try {
+				((PingTarget)conn).doPing();
+			} catch (Exception ex) {
+				if (ex instanceof SQLException) {
+					return (SQLException) ex;
+				}
+
+				return SQLError.createSQLException("Ping failed: " + ex.toString());
+			}
+		} else if (conn instanceof com.mysql.jdbc.Connection) {
 			if (pingMethod != null) {
 				try {
 					this.pingMethod.invoke(conn, null);
@@ -104,14 +115,16 @@
 			}
 		}
 
-		// Punt and use 'SELECT 1'
+		// Punt and use "/* ping */ SELECT 1" which will send
+		// pings across multi-connections too in case the connection
+		// was "wrapped" by Jboss in any way...
 
 		Statement pingStatement = null;
 
 		try {
 			pingStatement = conn.createStatement();
 			
-			pingStatement.executeQuery("SELECT 1").close();
+			pingStatement.executeQuery("/* ping */ SELECT 1").close();
 
 			return null;
 		} catch (SQLException sqlEx) {

Modified: trunk/src/testsuite/regression/MetaDataRegressionTest.java
===================================================================
--- trunk/src/testsuite/regression/MetaDataRegressionTest.java	2007-10-23 17:55:22 UTC (rev 6648)
+++ trunk/src/testsuite/regression/MetaDataRegressionTest.java	2007-10-23 18:01:29 UTC (rev 6649)
@@ -1961,6 +1961,10 @@
 	 * @throws Exception if the test fails.
 	 */
 	public void testBug27867() throws Exception {
+		if (!versionMeetsMinimum(4, 1)) {
+			return;
+		}
+		
 		try {
 			String gbkColumnName = "\u00e4\u00b8\u00ad\u00e6\u2013\u2021\u00e6\u00b5\u2039\u00e8\u00af\u2022";
 			createTable("ColumnNameEncoding", "(" + "`" + gbkColumnName
@@ -2067,4 +2071,50 @@
 					typeNameToPrecision.get(typeName));
 		}
 	}
+	
+	public void testBug20491() throws Exception {
+		try {
+			String[] fields = { "field1_ae_+			"field4_sz_+			
+			createTable("tst",
+					"(`" + fields[0] + "` int(10) unsigned NOT NULL default '0',"
+							+ "`" + fields[1] + "` varchar(45) default '',"
+							+ "`" + fields[2] + "` varchar(45) default '',"
+							+ "`" + fields[3] + "` varchar(45) default '',"
+							+ "PRIMARY KEY  (`" + fields[0] + "`))");
+
+			// demonstrate that these are all in the Cp1252 encoding
+			
+			for (int i = 0; i < fields.length; i++) {
+				assertEquals(fields[i], new String(fields[i].getBytes("Cp1252"), "Cp1252"));
+			}
+			
+			byte[] asBytes = fields[0].getBytes("utf-8");
+			
+			DatabaseMetaData md = this.conn.getMetaData();
+			
+			this.rs = md.getColumns(null, "%", "tst", "%");
+			
+			int j = 0;
+			
+			while (this.rs.next()) {
+				assertEquals("Wrong column name:" + this.rs.getString(4),
+						fields[j++], this.rs.getString(4));
+			}
+			
+			this.rs.close();
+			
+			this.rs = this.stmt.executeQuery("SELECT * FROM tst");
+			
+			ResultSetMetaData rsmd = this.rs.getMetaData();
+			
+			for (int i = 1; i <= rsmd.getColumnCount(); i++) {
+				assertEquals("Wrong column name:" + rsmd.getColumnName(i),
+						fields[i - 1], rsmd.getColumnName(i));
+			}
+		} finally {
+			closeMemberJDBCResources();
+		}
+	}
 }

Modified: trunk/src/testsuite/regression/ResultSetRegressionTest.java
===================================================================
--- trunk/src/testsuite/regression/ResultSetRegressionTest.java	2007-10-23 17:55:22 UTC (rev 6648)
+++ trunk/src/testsuite/regression/ResultSetRegressionTest.java	2007-10-23 18:01:29 UTC (rev 6649)
@@ -4401,7 +4401,10 @@
 	    noBlobConn = getConnectionWithProps(props);
 	    this.rs = noBlobConn.createStatement().executeQuery("SELECT concat(Class,petallength), COUNT(*) FROM `testBug24886` GROUP BY `concat(Class,petallength)`");
         this.rs.next();
-        assertEquals("java.lang.String", this.rs.getObject(1).getClass().getName());
+        
+        if (versionMeetsMinimum(4, 1)) {
+        	assertEquals("java.lang.String", this.rs.getObject(1).getClass().getName());
+        }
 	}
 
 	

Modified: trunk/src/testsuite/regression/StatementRegressionTest.java
===================================================================
--- trunk/src/testsuite/regression/StatementRegressionTest.java	2007-10-23 17:55:22 UTC (rev 6648)
+++ trunk/src/testsuite/regression/StatementRegressionTest.java	2007-10-23 18:01:29 UTC (rev 6649)
@@ -3486,6 +3486,7 @@
 				
 				try {
 					timeoutStmt.execute("SELECT SLEEP(30)");
+					fail("Query didn't time out");
 				} catch (MySQLTimeoutException timeoutEx) {
 					long end = System.currentTimeMillis();
 					
@@ -3898,7 +3899,9 @@
 			this.conn.setReadOnly(true);
 			this.stmt.execute("(SELECT 1) UNION (SELECT 2)");
 			this.conn.prepareStatement("(SELECT 1) UNION (SELECT 2)").execute();
-			((com.mysql.jdbc.Connection) this.conn).serverPrepareStatement("(SELECT 1) UNION (SELECT 2)").execute();
+			if (versionMeetsMinimum(4, 1)) {
+				((com.mysql.jdbc.Connection) this.conn).serverPrepareStatement("(SELECT 1) UNION (SELECT 2)").execute();
+			}
 		} finally {
 			this.conn.setReadOnly(false);
 		}

Thread
Connector/J commit: r6649 - in trunk: . src/com/mysql/jdbc src/com/mysql/jdbc/integration/jboss src/testsuite/regressionmmatthews23 Oct