Skip to content

Commit 900725f

Browse files
author
diego Dupin
committed
[CONJ-910] permit jdbc:mysql scheme when connection string contains "permitMysqlScheme" for compatibility
1 parent 9ab6f86 commit 900725f

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

src/main/java/org/mariadb/jdbc/Configuration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,9 @@ private Configuration(
474474
* @return true if url string correspond.
475475
*/
476476
public static boolean acceptsUrl(String url) {
477-
return url != null && url.startsWith("jdbc:mariadb:");
477+
return url != null
478+
&& (url.startsWith("jdbc:mariadb:")
479+
|| (url.startsWith("jdbc:mysql:") && url.contains("permitMysqlScheme")));
478480
}
479481

480482
public static Configuration parse(final String url) throws SQLException {

src/main/java/org/mariadb/jdbc/client/socket/impl/PacketWriter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,7 @@ private void checkMaxAllowedLength(int length) throws MaxAllowedPacketException
703703
}
704704

705705
public boolean throwMaxAllowedLength(int length) {
706-
if (maxAllowedPacket != null)
707-
return cmdLength + length >= maxAllowedPacket;
706+
if (maxAllowedPacket != null) return cmdLength + length >= maxAllowedPacket;
708707
return false;
709708
}
710709

src/test/java/org/mariadb/jdbc/integration/BatchTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,14 @@ public void largeBatch(Connection con) throws SQLException {
272272
public void bulkPacketSplitMaxAllowedPacket() throws SQLException {
273273
int maxAllowedPacket = getMaxAllowedPacket();
274274
bulkPacketSplit(2, maxAllowedPacket - 40, maxAllowedPacket);
275-
if (maxAllowedPacket >= 16 * 1024 * 1024)
276-
bulkPacketSplit(2, maxAllowedPacket - 40, null);
275+
if (maxAllowedPacket >= 16 * 1024 * 1024) bulkPacketSplit(2, maxAllowedPacket - 40, null);
277276
}
278277

279278
@Test
280279
public void bulkPacketSplitMultiplePacket() throws SQLException {
281280
int maxAllowedPacket = getMaxAllowedPacket();
282281
bulkPacketSplit(4, getMaxAllowedPacket() / 3, maxAllowedPacket);
283-
if (maxAllowedPacket >= 16 * 1024 * 1024)
284-
bulkPacketSplit(4, getMaxAllowedPacket() / 3, null);
282+
if (maxAllowedPacket >= 16 * 1024 * 1024) bulkPacketSplit(4, getMaxAllowedPacket() / 3, null);
285283
}
286284

287285
@Test
@@ -298,7 +296,10 @@ public void bulkPacketSplit(int nb, int len, Integer maxAllowedPacket) throws SQ
298296
arr[pos] = (byte) ((pos % 60) + 65);
299297
}
300298

301-
try (Connection con = createCon("&useServerPrepStmts&useBulkStmts" + (maxAllowedPacket != null ? "&maxAllowedPacket=" + maxAllowedPacket: ""))) {
299+
try (Connection con =
300+
createCon(
301+
"&useServerPrepStmts&useBulkStmts"
302+
+ (maxAllowedPacket != null ? "&maxAllowedPacket=" + maxAllowedPacket : ""))) {
302303
Statement stmt = con.createStatement();
303304
stmt.execute("TRUNCATE BatchTest");
304305
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER

src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,9 @@ public void pamAuthPlugin() throws Throwable {
836836
testPort = Integer.parseInt(System.getenv("TEST_PAM_PORT"));
837837
}
838838
String connStr =
839-
String.format(
840-
"jdbc:mariadb://%s:%s/%s?user=%s&password=%s&%s",
841-
hostname, testPort, database, pamUser, pamPwd, defaultOther);
839+
String.format(
840+
"jdbc:mariadb://%s:%s/%s?user=%s&password=%s&%s",
841+
hostname, testPort, database, pamUser, pamPwd, defaultOther);
842842
try {
843843
try (Connection connection =
844844
DriverManager.getConnection(connStr + "&restrictedAuth=dialog")) {

src/test/java/org/mariadb/jdbc/unit/util/ConfigurationTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public void testAcceptsUrl() {
159159
assertFalse(driver.acceptsURL(null));
160160
assertTrue(driver.acceptsURL("jdbc:mariadb://localhost/test"));
161161
assertFalse(driver.acceptsURL("jdbc:mysql://localhost/test"));
162+
assertTrue(driver.acceptsURL("jdbc:mysql://localhost/test?permitMysqlScheme"));
162163
}
163164

164165
@Test
@@ -191,6 +192,14 @@ public void testConfigurationIsolation() throws Throwable {
191192
assertTrue(
192193
e.getMessage().contains("Wrong argument value 'wrong_val' for TransactionIsolation"));
193194
}
195+
196+
Assertions.assertNull(
197+
Configuration.parse("jdbc:mysql://localhost/test?transactionIsolation=wrong_val"));
198+
199+
conf =
200+
Configuration.parse(
201+
"jdbc:mysql://localhost/test?transactionIsolation=SERIALIZABLE&permitMysqlScheme");
202+
assertTrue(TransactionIsolation.SERIALIZABLE == conf.transactionIsolation());
194203
}
195204

196205
@Test

0 commit comments

Comments
 (0)