Skip to content

Commit

Permalink
Fix for Bug#116630 (Bug#37272802), Tests fail on Windows if test data…
Browse files Browse the repository at this point in the history
…base has upper/mixed case chars.

Change-Id: Ibbd4e7abac97e4cac2baa5f82ca683035c67dec4
  • Loading branch information
fjssilva committed Nov 22, 2024
1 parent 3cdc8a2 commit 555db50
Show file tree
Hide file tree
Showing 16 changed files with 418 additions and 429 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 9.2.0

- Fix for Bug#116630 (Bug#37272802), Tests fail on Windows if test database has upper/mixed case chars.

- Fix for Bug#71143 (Bug#17967091), Calling ResultSet.updateRow should not set all field values in UPDATE.

- Fix for Bug#103437 (Bug#32807360), Syntax error when calling PreparedStatement.getMetadata() with LIMIT placeholded.
Expand Down
103 changes: 51 additions & 52 deletions src/main/core-impl/java/com/mysql/cj/CancelQueryTaskImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,64 +74,63 @@ public void run() {
}

try {
if (CancelQueryTaskImpl.this.queryTimeoutKillsConnection) {
localQueryToCancel.setCancelStatus(CancelStatus.CANCELED_BY_TIMEOUT);
session.invokeCleanupListeners(new OperationCancelledException(Messages.getString("Statement.ConnectionKilledDueToTimeout")));
} else {
localQueryToCancel.getCancelTimeoutLock().lock();
localQueryToCancel.getCancelTimeoutLock().lock();
try {
long origConnId = session.getThreadId();
HostInfo hostInfo = session.getHostInfo();
String database = hostInfo.getDatabase();
String user = hostInfo.getUser();
String password = hostInfo.getPassword();

NativeSession newSession = null;
try {
long origConnId = session.getThreadId();
HostInfo hostInfo = session.getHostInfo();
String database = hostInfo.getDatabase();
String user = hostInfo.getUser();
String password = hostInfo.getPassword();

NativeSession newSession = null;
try {
newSession = new NativeSession(hostInfo, session.getPropertySet());

TelemetrySpan span = newSession.getTelemetryHandler().startSpan(TelemetrySpanName.CANCEL_QUERY);
try (TelemetryScope scope = span.makeCurrent()) {
span.setAttribute(TelemetryAttribute.DB_NAME, database);
span.setAttribute(TelemetryAttribute.DB_OPERATION, TelemetryAttribute.OPERATION_KILL);
span.setAttribute(TelemetryAttribute.DB_STATEMENT, TelemetryAttribute.OPERATION_KILL + TelemetryAttribute.STATEMENT_SUFFIX);
span.setAttribute(TelemetryAttribute.DB_SYSTEM, TelemetryAttribute.DB_SYSTEM_DEFAULT);
span.setAttribute(TelemetryAttribute.DB_USER, user);
span.setAttribute(TelemetryAttribute.THREAD_ID, Thread.currentThread().getId());
span.setAttribute(TelemetryAttribute.THREAD_NAME, Thread.currentThread().getName());

newSession.connect(hostInfo, user, password, database, 30000, new TransactionEventHandler() {

@Override
public void transactionCompleted() {
}

@Override
public void transactionBegun() {
}

});
newSession.getProtocol().sendCommand(new NativeMessageBuilder(newSession.getServerSession().supportsQueryAttributes())
.buildComQuery(newSession.getSharedSendPacket(), newSession, "KILL QUERY " + origConnId), false, 0);
} catch (Throwable t) {
span.setError(t);
throw t;
} finally {
span.end();
}
newSession = new NativeSession(hostInfo, session.getPropertySet());

TelemetrySpan span = newSession.getTelemetryHandler().startSpan(TelemetrySpanName.CANCEL_QUERY);
try (TelemetryScope scope = span.makeCurrent()) {
span.setAttribute(TelemetryAttribute.DB_NAME, database);
span.setAttribute(TelemetryAttribute.DB_OPERATION, TelemetryAttribute.OPERATION_KILL);
span.setAttribute(TelemetryAttribute.DB_STATEMENT, TelemetryAttribute.OPERATION_KILL + TelemetryAttribute.STATEMENT_SUFFIX);
span.setAttribute(TelemetryAttribute.DB_SYSTEM, TelemetryAttribute.DB_SYSTEM_DEFAULT);
span.setAttribute(TelemetryAttribute.DB_USER, user);
span.setAttribute(TelemetryAttribute.THREAD_ID, Thread.currentThread().getId());
span.setAttribute(TelemetryAttribute.THREAD_NAME, Thread.currentThread().getName());

newSession.connect(hostInfo, user, password, database, 30000, new TransactionEventHandler() {

@Override
public void transactionCompleted() {
}

@Override
public void transactionBegun() {
}

});
newSession.getProtocol().sendCommand(new NativeMessageBuilder(newSession.getServerSession().supportsQueryAttributes())
.buildComQuery(newSession.getSharedSendPacket(), newSession, "KILL QUERY " + origConnId), false, 0);
} catch (Throwable t) {
span.setError(t);
throw t;
} finally {
try {
newSession.forceClose();
} catch (Throwable t) {
// no-op.
}
span.end();
}
localQueryToCancel.setCancelStatus(CancelStatus.CANCELED_BY_TIMEOUT);
} finally {
localQueryToCancel.getCancelTimeoutLock().unlock();
try {
newSession.forceClose();
} catch (Throwable t) {
// no-op.
}
}
localQueryToCancel.setCancelStatus(CancelStatus.CANCELED_BY_TIMEOUT);
} finally {
localQueryToCancel.getCancelTimeoutLock().unlock();
}

if (CancelQueryTaskImpl.this.queryTimeoutKillsConnection) {
session.invokeCleanupListeners(new OperationCancelledException(Messages.getString("Statement.ConnectionKilledDueToTimeout")));
}
// } catch (NullPointerException npe) {
} catch (NullPointerException npe) {
// Case when connection closed while starting to cancel.
// We can't easily synchronize this, because then one thread can't cancel() a running query.
// Ignore, we shouldn't re-throw this, because the connection's already closed, so the statement has been timed out.
Expand Down
2 changes: 1 addition & 1 deletion src/main/core-impl/java/com/mysql/cj/NativeSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ public Timer getCancelTimer() {
getSessionLock().lock();
try {
if (this.cancelTimer == null) {
this.cancelTimer = new Timer("MySQL Statement Cancellation Timer", Boolean.TRUE);
this.cancelTimer = new Timer("MySQL Statement Cancellation Timer", true);
}
return this.cancelTimer;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Wrapper;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
Expand Down Expand Up @@ -2279,7 +2278,7 @@ private void setInOutParamsOnServer() throws SQLException {
ClientPreparedStatement setPstmt = null;

try {
setPstmt = ((Wrapper) this.connection.clientPrepareStatement(queryBuf.toString())).unwrap(ClientPreparedStatement.class);
setPstmt = this.connection.clientPrepareStatement(queryBuf.toString()).unwrap(ClientPreparedStatement.class);
setPstmt.getQueryBindings().setFromBindValue(0, ((PreparedQuery) this.query).getQueryBindings().getBindValues()[inParamInfo.index]);
setPstmt.executeUpdate();
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.lang.reflect.Method;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSetMetaData;
Expand Down Expand Up @@ -281,7 +282,7 @@ public void testBug9682() throws Exception {
}

/**
* Tests fix forBUG#10310 - Driver doesn't support {?=CALL(...)} for calling stored functions.
* Tests fix for BUG#10310 - Driver doesn't support {?=CALL(...)} for calling stored functions.
* This involved adding support for function retrieval to DatabaseMetaData.getProcedures() and getProcedureColumns() as well.
*
* @throws Exception
Expand Down Expand Up @@ -411,9 +412,7 @@ public void testBug10310() throws Exception {
@Test
public void testBug12417() throws Exception {
if (isServerRunningOnWindows()) {

createProcedure("testBug12417", "()\nBEGIN\nSELECT 1;end\n");

Connection ucCatalogConn = null;

try {
Expand All @@ -428,6 +427,11 @@ public void testBug12417() throws Exception {
}
}

/**
* Tests fix for Bug#15121 - a faulty procedure is executed but no exception is thrown.
*
* @throws Exception
*/
@Test
public void testBug15121() throws Exception {
createProcedure("p_testBug15121", "()\nBEGIN\nSELECT * from idonotexist;\nEND");
Expand All @@ -438,15 +442,17 @@ public void testBug15121() throws Exception {
props.setProperty(PropertyKey.DBNAME.getKeyName(), "");

Connection noDbConn = getConnectionWithProps(props);
DatabaseMetaData dbmd = noDbConn.getMetaData();

StringBuilder queryBuf = new StringBuilder("{call ");
String quotedId = this.conn.getMetaData().getIdentifierQuoteString();
String quotedId = dbmd.getIdentifierQuoteString();
queryBuf.append(quotedId);
queryBuf.append(this.conn.getCatalog());
queryBuf.append(quotedId);
queryBuf.append(".p_testBug15121()}");

assertThrows(SQLException.class, "Table '" + this.conn.getCatalog() + ".idonotexist' doesn't exist", () -> {
String db = dbmd.storesLowerCaseIdentifiers() ? this.conn.getCatalog().toLowerCase() : this.conn.getCatalog();
assertThrows(SQLException.class, "Table '" + db + ".idonotexist' doesn't exist", () -> {
noDbConn.prepareCall(queryBuf.toString()).execute();
return null;
});
Expand Down
22 changes: 7 additions & 15 deletions src/test/java/testsuite/regression/CharsetRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import com.mysql.cj.conf.PropertyDefinitions.SslMode;
import com.mysql.cj.conf.PropertyKey;
import com.mysql.cj.exceptions.ExceptionFactory;
import com.mysql.cj.exceptions.MysqlErrorNumbers;
import com.mysql.cj.interceptors.QueryInterceptor;
import com.mysql.cj.jdbc.JdbcConnection;
import com.mysql.cj.log.Log;
Expand Down Expand Up @@ -312,9 +311,12 @@ public void testBug64205() throws Exception {
Properties props = getPropertiesFromTestsuiteUrl();
String dbname = props.getProperty(PropertyKey.DBNAME.getKeyName());
if (dbname == null) {
assertTrue(false, "No database selected");
fail("No database selected");
}

boolean lowerCaseIds = this.conn.getMetaData().storesLowerCaseIdentifiers();
String expectedDbName = lowerCaseIds ? dbname.toLowerCase() : dbname;

props = new Properties();
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
props.setProperty(PropertyKey.characterEncoding.getKeyName(), "EUC_JP");
Expand All @@ -328,10 +330,7 @@ public void testBug64205() throws Exception {
testRs = testSt.executeQuery("SELECT * FROM `" + dbname + "`.`\u307b\u3052\u307b\u3052`");
} catch (SQLException e1) {
if (e1.getClass().getName().endsWith("SQLSyntaxErrorException")) {
assertEquals("Table '" + dbname + ".\u307B\u3052\u307b\u3052' doesn't exist", e1.getMessage());
} else if (e1.getErrorCode() == MysqlErrorNumbers.ER_FILE_NOT_FOUND) {
// this could happen on Windows with 5.5 and 5.6 servers where BUG#14642248 exists
assertTrue(e1.getMessage().contains("Can't find file"));
assertEquals("Table '" + expectedDbName + ".\u307B\u3052\u307b\u3052' doesn't exist", e1.getMessage());
} else {
throw e1;
}
Expand All @@ -347,12 +346,8 @@ public void testBug64205() throws Exception {
testRs = testSt.executeQuery("SELECT * FROM `" + dbname + "`.`\u307b\u3052\u307b\u3052`");
} catch (SQLException e2) {
if (e2.getClass().getName().endsWith("SQLSyntaxErrorException")) {
assertEquals("\u0422\u0430\u0431\u043b\u0438\u0446\u0430 '" + dbname
assertEquals("\u0422\u0430\u0431\u043b\u0438\u0446\u0430 '" + expectedDbName
+ ".\u307b\u3052\u307b\u3052' \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442", e2.getMessage());
} else if (e2.getErrorCode() == MysqlErrorNumbers.ER_FILE_NOT_FOUND) {
// this could happen on Windows with 5.5 and 5.6 servers where BUG#14642248 exists
assertTrue(e2.getMessage().indexOf("\u0444\u0430\u0439\u043b") > -1,
"File not found error message should be russian but is this one: " + e2.getMessage());
} else {
throw e2;
}
Expand Down Expand Up @@ -380,10 +375,7 @@ public void testBug64205() throws Exception {
fail("Exception should be thrown for attemping to query non-existing table");
} catch (SQLException e1) {
if (e1.getClass().getName().endsWith("SQLSyntaxErrorException")) {
assertEquals("Table '" + dbname + ".\u307B\u3052\u307b\u3052' doesn't exist", e1.getMessage());
} else if (e1.getErrorCode() == MysqlErrorNumbers.ER_FILE_NOT_FOUND) {
// this could happen on Windows with 5.5 and 5.6 servers where BUG#14642248 exists
assertTrue(e1.getMessage().contains("Can't find file"));
assertEquals("Table '" + expectedDbName + ".\u307B\u3052\u307b\u3052' doesn't exist", e1.getMessage());
} else {
throw e1;
}
Expand Down
Loading

0 comments on commit 555db50

Please sign in to comment.