Modified:
branches/branch_3_1/connector-j/src/com/mysql/jdbc/Connection.java
branches/branch_3_1/connector-j/src/com/mysql/jdbc/NonRegisteringDriver.java
branches/branch_3_1/connector-j/src/testsuite/BaseTestCase.java
branches/branch_3_1/connector-j/src/testsuite/regression/ConnectionRegressionTest.java
Log:
- Fixed BUG#13453 - URL configuration parameters don't allow
'&' or '=' in their values. The JDBC driver now parses
configuration parameters as if they are encoded using the
application/x-www-form-urlencoded format as specified
by java.net.URLDecoder -
http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLDecoder.html
If the '%' character is present in a configuration property,
it must now be represented as %25, which is the encoded form
of '%' when using application/x-www-form-urlencoded encoding.
- The configuration property "sessionVariables" now allows you to
specify variables that start with the "@" sign.
Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/Connection.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/Connection.java 2005-09-26 00:06:54 UTC (rev 4306)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/Connection.java 2005-09-26 19:23:55 UTC (rev 4307)
@@ -5098,8 +5098,12 @@
for (int i = 0; i < numVariablesToSet; i++) {
String variableValuePair = (String) variablesToSet.get(i);
-
- stmt.executeUpdate("SET SESSION " + variableValuePair);
+
+ if (variableValuePair.startsWith("@")) {
+ stmt.executeUpdate("SET " + variableValuePair);
+ } else {
+ stmt.executeUpdate("SET SESSION " + variableValuePair);
+ }
}
} finally {
if (stmt != null) {
Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/NonRegisteringDriver.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/NonRegisteringDriver.java 2005-09-26 00:06:54 UTC (rev 4306)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/NonRegisteringDriver.java 2005-09-26 19:23:55 UTC (rev 4307)
@@ -26,6 +26,8 @@
import java.io.IOException;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
@@ -473,7 +475,12 @@
if ((value != null && value.length() > 0) &&
(parameter != null && parameter.length() > 0)) {
- urlProps.put(parameter, value);
+ try {
+ urlProps.put(parameter, URLDecoder.decode(value, "UTF-8"));
+ } catch (UnsupportedEncodingException badEncoding) {
+ // punt
+ urlProps.put(parameter, value);
+ }
}
}
}
Modified: branches/branch_3_1/connector-j/src/testsuite/BaseTestCase.java
===================================================================
--- branches/branch_3_1/connector-j/src/testsuite/BaseTestCase.java 2005-09-26 00:06:54 UTC (rev 4306)
+++ branches/branch_3_1/connector-j/src/testsuite/BaseTestCase.java 2005-09-26 19:23:55 UTC (rev 4307)
@@ -52,6 +52,8 @@
public abstract class BaseTestCase extends TestCase {
private final static String ADMIN_CONNECTION_PROPERTY_NAME = "com.mysql.jdbc.testsuite.admin-url";
+ private final static String NO_MULTI_HOST_PROPERTY_NAME = "com.mysql.jdbc.testsuite.no-multi-hosts-tests";
+
/**
* JDBC URL, initialized from com.mysql.jdbc.testsuite.url system property,
* or defaults to jdbc:mysql:///test
@@ -347,6 +349,10 @@
return (prop != null) && (prop.length() > 0);
}
+
+ protected boolean runMultiHostTests() {
+ return !runTestIfSysPropDefined(NO_MULTI_HOST_PROPERTY_NAME);
+ }
/**
* Creates resources used by all tests.
Modified: branches/branch_3_1/connector-j/src/testsuite/regression/ConnectionRegressionTest.java
===================================================================
--- branches/branch_3_1/connector-j/src/testsuite/regression/ConnectionRegressionTest.java 2005-09-26 00:06:54 UTC (rev 4306)
+++ branches/branch_3_1/connector-j/src/testsuite/regression/ConnectionRegressionTest.java 2005-09-26 19:23:55 UTC (rev 4307)
@@ -956,61 +956,63 @@
* @throws Exception
*/
public void testBug8643() throws Exception {
- Properties defaultProps = getMasterSlaveProps();
-
- defaultProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
- defaultProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);
-
- defaultProps.put("autoReconnect", "true");
- defaultProps.put("roundRobinLoadBalance", "true");
- defaultProps.put("failOverReadOnly", "false");
-
- Connection con = null;
- try {
- con = DriverManager
- .getConnection(getMasterSlaveUrl(), defaultProps);
- Statement stmt1 = con.createStatement();
-
- ResultSet rs1 = stmt1.executeQuery("show variables like 'port'");
- rs1.next();
-
- rs1 = stmt1.executeQuery("select connection_id()");
- rs1.next();
- String originalConnectionId = rs1.getString(1);
- stmt1.executeUpdate("kill " + originalConnectionId);
+ if (runMultiHostTests()) {
+ Properties defaultProps = getMasterSlaveProps();
+
+ defaultProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
+ defaultProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);
+
+ defaultProps.put("autoReconnect", "true");
+ defaultProps.put("roundRobinLoadBalance", "true");
+ defaultProps.put("failOverReadOnly", "false");
+
+ Connection con = null;
try {
- rs1 = stmt1.executeQuery("show variables like 'port'");
- } catch (SQLException ex) {
- // failover and retry
- rs1 = stmt1.executeQuery("show variables like 'port'");
- }
- rs1.next();
- assertTrue(!((com.mysql.jdbc.Connection) con).isMasterConnection());
-
- rs1 = stmt1.executeQuery("select connection_id()");
- rs1.next();
- String nextConnectionId = rs1.getString(1);
- assertTrue(!nextConnectionId.equals(originalConnectionId));
-
- stmt1.executeUpdate("kill " + nextConnectionId);
-
- try {
- rs1 = stmt1.executeQuery("show variables like 'port'");
- } catch (SQLException ex) {
- // failover and retry
- rs1 = stmt1.executeQuery("show variables like 'port'");
- }
-
- rs1.next();
- assertTrue(((com.mysql.jdbc.Connection) con).isMasterConnection());
-
- } finally {
- if (con != null) {
+ con = DriverManager
+ .getConnection(getMasterSlaveUrl(), defaultProps);
+ Statement stmt1 = con.createStatement();
+
+ ResultSet rs1 = stmt1.executeQuery("show variables like 'port'");
+ rs1.next();
+
+ rs1 = stmt1.executeQuery("select connection_id()");
+ rs1.next();
+ String originalConnectionId = rs1.getString(1);
+ stmt1.executeUpdate("kill " + originalConnectionId);
try {
- con.close();
- } catch (Exception e) {
- e.printStackTrace();
+ rs1 = stmt1.executeQuery("show variables like 'port'");
+ } catch (SQLException ex) {
+ // failover and retry
+ rs1 = stmt1.executeQuery("show variables like 'port'");
}
+ rs1.next();
+ assertTrue(!((com.mysql.jdbc.Connection) con).isMasterConnection());
+
+ rs1 = stmt1.executeQuery("select connection_id()");
+ rs1.next();
+ String nextConnectionId = rs1.getString(1);
+ assertTrue(!nextConnectionId.equals(originalConnectionId));
+
+ stmt1.executeUpdate("kill " + nextConnectionId);
+
+ try {
+ rs1 = stmt1.executeQuery("show variables like 'port'");
+ } catch (SQLException ex) {
+ // failover and retry
+ rs1 = stmt1.executeQuery("show variables like 'port'");
+ }
+
+ rs1.next();
+ assertTrue(((com.mysql.jdbc.Connection) con).isMasterConnection());
+
+ } finally {
+ if (con != null) {
+ try {
+ con.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
}
}
@@ -1117,15 +1119,17 @@
* @throws Exception if the test fails
*/
public void testBug11879() throws Exception {
- Connection replConn = null;
-
- try {
- replConn = getMasterSlaveReplicationConnection();
- replConn.setReadOnly(true);
- replConn.setReadOnly(false);
- } finally {
- if (replConn != null) {
- replConn.close();
+ if (runMultiHostTests()) {
+ Connection replConn = null;
+
+ try {
+ replConn = getMasterSlaveReplicationConnection();
+ replConn.setReadOnly(true);
+ replConn.setReadOnly(false);
+ } finally {
+ if (replConn != null) {
+ replConn.close();
+ }
}
}
}
@@ -1151,15 +1155,17 @@
* @throws Exception if the test fails.
*/
public void testBug12218() throws Exception {
- Connection replConn = null;
-
- try {
- replConn = getMasterSlaveReplicationConnection();
- assertTrue(!((ReplicationConnection)replConn).getMasterConnection().hasSameProperties(
- ((ReplicationConnection)replConn).getSlavesConnection()));
- } finally {
- if (replConn != null) {
- replConn.close();
+ if (runMultiHostTests()) {
+ Connection replConn = null;
+
+ try {
+ replConn = getMasterSlaveReplicationConnection();
+ assertTrue(!((ReplicationConnection)replConn).getMasterConnection().hasSameProperties(
+ ((ReplicationConnection)replConn).getSlavesConnection()));
+ } finally {
+ if (replConn != null) {
+ replConn.close();
+ }
}
}
}
@@ -1234,6 +1240,44 @@
}
}
}
+
+ /**
+ * Tests fix for BUG#13453 - can't use & or = in URL configuration
+ * values (we now allow you to use www-form-encoding).
+ *
+ * @throws Exception if the test fails
+ */
+ public void testBug13453() throws Exception {
+ StringBuffer urlBuf = new StringBuffer(dbUrl);
+
+ if (dbUrl.indexOf('?') == -1) {
+ urlBuf.append('?');
+ } else if (dbUrl.indexOf('&') != -1) {
+ urlBuf.append('&');
+ }
+
+ urlBuf.append("sessionVariables=@testBug13453='%25%26+%3D'");
+
+ Connection encodedConn = null;
+
+ try {
+ encodedConn = DriverManager.getConnection(urlBuf.toString(), null);
+
+ this.rs = encodedConn.createStatement().executeQuery("SELECT @testBug13453");
+ assertTrue(this.rs.next());
+ assertEquals("%& =", this.rs.getString(1));
+ } finally {
+ if (this.rs != null) {
+ this.rs.close();
+ this.rs = null;
+ }
+
+ if (encodedConn != null) {
+ encodedConn.close();
+ }
+ }
+ }
+
public void testCSC5765() throws Exception {
Properties props = new Properties();
props.setProperty("useUnicode","true");
| Thread |
|---|
| • Connector/J commit: r4307 - in branches/branch_3_1/connector-j/src: com/mysql/jdbc testsuite testsuite/regression | mmatthews | 26 Sep |