Skip to content

Commit

Permalink
Fix for Bug#26399958, UNABLE TO CONNECT TO MYSQL 8.0.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
soklakov committed Jul 6, 2017
1 parent bacf5a1 commit 1d14b69
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 16 additions & 4 deletions src/com/mysql/jdbc/ConnectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
Expand All @@ -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()) {
Expand Down
7 changes: 6 additions & 1 deletion src/testsuite/perf/RetrievalPerfTest.java
Original file line number Diff line number Diff line change
@@ -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
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
Expand All @@ -23,6 +23,8 @@

package testsuite.perf;

import com.mysql.jdbc.ConnectionImpl;

import testsuite.BaseTestCase;

/**
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 9 additions & 2 deletions src/testsuite/regression/ConnectionRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")) {
Expand Down Expand Up @@ -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))) {
Expand Down

0 comments on commit 1d14b69

Please sign in to comment.