From cfc78706659b0c0cd37a1ce18d7d637c09717e5b Mon Sep 17 00:00:00 2001 From: Alexander Soklakov Date: Thu, 20 Jul 2017 12:11:24 +0400 Subject: [PATCH] Fix for Bug#26440544, CONNECTOR/J SHOULD NOT USE TX_{READ_ONLY,ISOLATION} WHICH IS PLANNED FOR REMOVAL. --- CHANGES | 1 + src/com/mysql/jdbc/ConnectionImpl.java | 24 +++++++++---------- .../regression/ConnectionRegressionTest.java | 10 ++++++-- src/testsuite/simple/ConnectionTest.java | 9 ++++--- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/CHANGES b/CHANGES index e59be0fac..4f9c4f334 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,7 @@ Version 5.1.44 + - Fix for Bug#26440544, CONNECTOR/J SHOULD NOT USE TX_{READ_ONLY,ISOLATION} WHICH IS PLANNED FOR REMOVAL. Version 5.1.43 diff --git a/src/com/mysql/jdbc/ConnectionImpl.java b/src/com/mysql/jdbc/ConnectionImpl.java index 1383b503b..3fa8903f5 100644 --- a/src/com/mysql/jdbc/ConnectionImpl.java +++ b/src/com/mysql/jdbc/ConnectionImpl.java @@ -1280,14 +1280,7 @@ private void checkServerEncoding() throws SQLException { * @throws SQLException */ private void checkTransactionIsolationLevel() throws SQLException { - String txIsolationName = null; - - if (versionMeetsMinimum(4, 0, 3)) { - txIsolationName = "tx_isolation"; - } else { - txIsolationName = "transaction_isolation"; - } - + String txIsolationName = versionMeetsMinimum(4, 0, 3) && !versionMeetsMinimum(8, 0, 3) ? "tx_isolation" : "transaction_isolation"; String s = this.serverVariables.get(txIsolationName); if (s != null) { @@ -3001,11 +2994,12 @@ public int getTransactionIsolation() throws SQLException { String query = null; - int offset = 0; + int offset = 1; - if (versionMeetsMinimum(4, 0, 3)) { + if (versionMeetsMinimum(8, 0, 3)) { + query = "SELECT @@session.transaction_isolation"; + } else if (versionMeetsMinimum(4, 0, 3)) { query = "SELECT @@session.tx_isolation"; - offset = 1; } else { query = "SHOW VARIABLES LIKE 'transaction_isolation'"; offset = 2; @@ -3548,7 +3542,7 @@ public boolean isReadOnly(boolean useSessionStatus) throws SQLException { try { stmt = getMetadataSafeStatement(); - rs = stmt.executeQuery("select @@session.tx_read_only"); + rs = stmt.executeQuery(versionMeetsMinimum(8, 0, 3) ? "select @@session.transaction_read_only" : "select @@session.tx_read_only"); if (rs.next()) { return rs.getInt(1) != 0; // mysql has a habit of tri+ state booleans } @@ -3786,7 +3780,11 @@ private void loadServerVariables() throws SQLException { queryBuf.append(", @@sql_mode AS sql_mode"); queryBuf.append(", @@system_time_zone AS system_time_zone"); queryBuf.append(", @@time_zone AS time_zone"); - queryBuf.append(", @@tx_isolation AS tx_isolation"); + if (versionMeetsMinimum(8, 0, 3)) { + queryBuf.append(", @@transaction_isolation AS transaction_isolation"); + } else { + queryBuf.append(", @@tx_isolation AS tx_isolation"); + } queryBuf.append(", @@wait_timeout AS wait_timeout"); results = stmt.executeQuery(queryBuf.toString()); diff --git a/src/testsuite/regression/ConnectionRegressionTest.java b/src/testsuite/regression/ConnectionRegressionTest.java index c3f728b94..c0cfa3a9c 100644 --- a/src/testsuite/regression/ConnectionRegressionTest.java +++ b/src/testsuite/regression/ConnectionRegressionTest.java @@ -1805,7 +1805,9 @@ public void testBug27655() throws Exception { loggedConn = getConnectionWithProps(props); loggedConn.getTransactionIsolation(); - if (versionMeetsMinimum(4, 0, 3)) { + if (versionMeetsMinimum(8, 0, 3)) { + assertEquals(-1, StandardLogger.getBuffer().toString().indexOf("SHOW VARIABLES LIKE 'transaction_isolation'")); + } else if (versionMeetsMinimum(4, 0, 3)) { assertEquals(-1, StandardLogger.getBuffer().toString().indexOf("SHOW VARIABLES LIKE 'tx_isolation'")); } } finally { @@ -7555,7 +7557,11 @@ public void testBug75592() throws Exception { assertEquals(serverVariables.get("system_time_zone"), con.getServerVariable("system_time_zone")); assertEquals(serverVariables.get("time_zone"), con.getServerVariable("time_zone")); - assertEquals(serverVariables.get("tx_isolation"), con.getServerVariable("tx_isolation")); + if (con.versionMeetsMinimum(8, 0, 3)) { + assertEquals(serverVariables.get("transaction_isolation"), con.getServerVariable("transaction_isolation")); + } else { + assertEquals(serverVariables.get("tx_isolation"), con.getServerVariable("tx_isolation")); + } assertEquals(serverVariables.get("wait_timeout"), con.getServerVariable("wait_timeout")); if (!versionMeetsMinimum(5, 5, 0)) { assertEquals(serverVariables.get("language"), con.getServerVariable("language")); diff --git a/src/testsuite/simple/ConnectionTest.java b/src/testsuite/simple/ConnectionTest.java index 07bcd42a3..71ad05215 100644 --- a/src/testsuite/simple/ConnectionTest.java +++ b/src/testsuite/simple/ConnectionTest.java @@ -862,8 +862,9 @@ public void testUseLocalSessionState() throws Exception { conn1.getTransactionIsolation(); String logAsString = StandardLogger.getBuffer().toString(); + String txIsolationName = versionMeetsMinimum(4, 0, 3) && !versionMeetsMinimum(8, 0, 3) ? "tx_isolation" : "transaction_isolation"; - assertTrue(logAsString.indexOf("SET SESSION") == -1 && logAsString.indexOf("SHOW VARIABLES LIKE 'tx_isolation'") == -1 + assertTrue(logAsString.indexOf("SET SESSION") == -1 && logAsString.indexOf("SHOW VARIABLES LIKE '" + txIsolationName + "'") == -1 && logAsString.indexOf("SET autocommit=") == -1); } @@ -1715,6 +1716,8 @@ public void testReadOnly56() throws Exception { Connection localState = getConnectionWithProps("profileSql=true,useLocalSessionState=true"); + String txReadOnlyName = versionMeetsMinimum(8, 0, 3) ? "transaction_read_only" : "tx_read_only"; + for (int i = 0; i < 2; i++) { StandardLogger.startLoggingToBuffer(); localState.setReadOnly(true); @@ -1725,7 +1728,7 @@ public void testReadOnly56() throws Exception { } StandardLogger.startLoggingToBuffer(); localState.isReadOnly(); - assertTrue(StandardLogger.getBuffer().toString().indexOf("select @@session.tx_read_only") == -1); + assertTrue(StandardLogger.getBuffer().toString().indexOf("select @@session." + txReadOnlyName) == -1); } Connection noOptimization = getConnectionWithProps("profileSql=true,readOnlyPropagatesToServer=false"); @@ -1736,7 +1739,7 @@ public void testReadOnly56() throws Exception { assertTrue(StandardLogger.getBuffer().toString().indexOf("set session transaction read only") == -1); StandardLogger.startLoggingToBuffer(); noOptimization.isReadOnly(); - assertTrue(StandardLogger.getBuffer().toString().indexOf("select @@session.tx_read_only") == -1); + assertTrue(StandardLogger.getBuffer().toString().indexOf("select @@session." + txReadOnlyName) == -1); } } finally { StandardLogger.dropBuffer();