From 1d14b699eff3e6112aaedb1cbe5a151ab81f98f1 Mon Sep 17 00:00:00 2001 From: Alexander Soklakov Date: Thu, 6 Jul 2017 19:15:24 +0400 Subject: [PATCH] Fix for Bug#26399958, UNABLE TO CONNECT TO MYSQL 8.0.3. --- CHANGES | 2 ++ src/com/mysql/jdbc/ConnectionImpl.java | 20 +++++++++++++++---- src/testsuite/perf/RetrievalPerfTest.java | 7 ++++++- .../regression/ConnectionRegressionTest.java | 11 ++++++++-- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 500af3f06..78ce51584 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,8 @@ Version 5.1.43 + - Fix for Bug#26399958, UNABLE TO CONNECT TO MYSQL 8.0.3. + - Fix for Bug#78313 (21931572), proxies not handling Object.equals(Object) calls correctly. - Fix for Bug#85885 (25874048), resultSetConcurrency and resultSetType are swapped in call to prepareStatement. diff --git a/src/com/mysql/jdbc/ConnectionImpl.java b/src/com/mysql/jdbc/ConnectionImpl.java index fd1711823..bb488e783 100644 --- a/src/com/mysql/jdbc/ConnectionImpl.java +++ b/src/com/mysql/jdbc/ConnectionImpl.java @@ -3398,8 +3398,9 @@ private void initializePropsFromServer() throws SQLException { setupServerForTruncationChecks(); } - private boolean isQueryCacheEnabled() { - return "ON".equalsIgnoreCase(this.serverVariables.get("query_cache_type")) && !"0".equalsIgnoreCase(this.serverVariables.get("query_cache_size")); + public boolean isQueryCacheEnabled() { + return "YES".equalsIgnoreCase(this.serverVariables.get("have_query_cache")) && "ON".equalsIgnoreCase(this.serverVariables.get("query_cache_type")) + && !"0".equalsIgnoreCase(this.serverVariables.get("query_cache_size")); } private int getServerVariableAsInt(String variableName, int fallbackValue) throws SQLException { @@ -3776,8 +3777,7 @@ private void loadServerVariables() throws SQLException { queryBuf.append(", @@max_allowed_packet AS max_allowed_packet"); queryBuf.append(", @@net_buffer_length AS net_buffer_length"); queryBuf.append(", @@net_write_timeout AS net_write_timeout"); - queryBuf.append(", @@query_cache_size AS query_cache_size"); - queryBuf.append(", @@query_cache_type AS query_cache_type"); + queryBuf.append(", @@have_query_cache AS have_query_cache"); queryBuf.append(", @@sql_mode AS sql_mode"); queryBuf.append(", @@system_time_zone AS system_time_zone"); queryBuf.append(", @@time_zone AS time_zone"); @@ -3791,6 +3791,18 @@ private void loadServerVariables() throws SQLException { this.serverVariables.put(rsmd.getColumnLabel(i), results.getString(i)); } } + + if ("YES".equalsIgnoreCase(this.serverVariables.get("have_query_cache"))) { + results.close(); + results = stmt.executeQuery("SELECT @@query_cache_size AS query_cache_size, @@query_cache_type AS query_cache_type"); + if (results.next()) { + ResultSetMetaData rsmd = results.getMetaData(); + for (int i = 1; i <= rsmd.getColumnCount(); i++) { + this.serverVariables.put(rsmd.getColumnLabel(i), results.getString(i)); + } + } + } + } else { results = stmt.executeQuery(versionComment + "SHOW VARIABLES"); while (results.next()) { diff --git a/src/testsuite/perf/RetrievalPerfTest.java b/src/testsuite/perf/RetrievalPerfTest.java index e2c056b86..3a6734ce3 100644 --- a/src/testsuite/perf/RetrievalPerfTest.java +++ b/src/testsuite/perf/RetrievalPerfTest.java @@ -1,5 +1,5 @@ /* - Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved. The MySQL Connector/J is licensed under the terms of the GPLv2 , like most MySQL Connectors. @@ -23,6 +23,8 @@ package testsuite.perf; +import com.mysql.jdbc.ConnectionImpl; + import testsuite.BaseTestCase; /** @@ -79,6 +81,9 @@ public void setUp() throws Exception { * if an error occurs */ public void testRetrievalCached() throws Exception { + if (!((ConnectionImpl) this.conn).isQueryCacheEnabled()) { + return; + } this.stmt.executeUpdate("SET QUERY_CACHE_TYPE = DEMAND"); double fullBegin = System.currentTimeMillis(); diff --git a/src/testsuite/regression/ConnectionRegressionTest.java b/src/testsuite/regression/ConnectionRegressionTest.java index 64c241e54..0c800560b 100644 --- a/src/testsuite/regression/ConnectionRegressionTest.java +++ b/src/testsuite/regression/ConnectionRegressionTest.java @@ -7538,8 +7538,11 @@ public void testBug75592() throws Exception { assertEquals(serverVariables.get("max_allowed_packet"), con.getServerVariable("max_allowed_packet")); assertEquals(serverVariables.get("net_buffer_length"), con.getServerVariable("net_buffer_length")); assertEquals(serverVariables.get("net_write_timeout"), con.getServerVariable("net_write_timeout")); - assertEquals(serverVariables.get("query_cache_size"), con.getServerVariable("query_cache_size")); - assertEquals(serverVariables.get("query_cache_type"), con.getServerVariable("query_cache_type")); + assertEquals(serverVariables.get("have_query_cache"), con.getServerVariable("have_query_cache")); + if ("YES".equalsIgnoreCase(serverVariables.get("have_query_cache"))) { + assertEquals(serverVariables.get("query_cache_size"), con.getServerVariable("query_cache_size")); + assertEquals(serverVariables.get("query_cache_type"), con.getServerVariable("query_cache_type")); + } // not necessarily contains STRICT_TRANS_TABLES for (String sm : serverVariables.get("sql_mode").split(",")) { @@ -9823,6 +9826,10 @@ public void testBug77649() throws Exception { * This test requires a server started with the options '--query_cache_type=1' and '--query_cache_size=N', (N > 0). */ public void testBug74711() throws Exception { + if (!((ConnectionImpl) this.conn).isQueryCacheEnabled()) { + System.err.println("Warning! testBug77411() requires a server supporting a query cache."); + return; + } this.rs = this.stmt.executeQuery("SELECT @@global.query_cache_type, @@global.query_cache_size"); this.rs.next(); if (!"ON".equalsIgnoreCase(this.rs.getString(1)) || "0".equals(this.rs.getString(2))) {