Skip to content

Commit

Permalink
[fix][driver-mysql] Mysql Connection disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
guojn1 authored and astor-oss committed Jun 16, 2023
1 parent b56629c commit 8dde3c4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public void execute(@NonNull SqlSetPassword sqlSetPassword, CalcitePrepare.Conte
userDefinition.setPassword(sqlSetPassword.password);
userService.updateUser(userDefinition);
} else {
throw DINGO_RESOURCE.NoMatchingRowForUser().ex();
throw DINGO_RESOURCE.noMatchingRowForUser().ex();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public interface DingoResource {
ExInst<DingoSqlException> alterUserFailed(String a0, String a1);

@BaseMessage("Can't find any matching row in the user table")
ExInst<DingoSqlException> NoMatchingRowForUser();
ExInst<DingoSqlException> noMatchingRowForUser();

@BaseMessage("You have an error in your SQL syntax")
ExInst<DingoSqlException> parseSqlSyntaxError();

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,16 @@ public static void executeShowFields(String table, AtomicLong packetId, MysqlCon

public void execute(QueryPacket queryPacket,
MysqlConnection mysqlConnection) {
String sqlCommand = new String(queryPacket.message);
String[] sqlItems = sqlCommand.split(";");
String sql = new String(queryPacket.message);
AtomicLong packetId = new AtomicLong(queryPacket.packetId + 1);
for (String sql : sqlItems) {
if (log.isDebugEnabled()) {
log.debug("receive sql:" + sql);
}
if (mysqlConnection.passwordExpire && !doExpire(mysqlConnection, sql, packetId)) {
MysqlResponseHandler.responseError(packetId, mysqlConnection.channel, ErrorCode.ER_PASSWORD_EXPIRE);
return;
}
executeSingleQuery(sql, packetId, mysqlConnection);
if (log.isDebugEnabled()) {
log.debug("receive sql:" + sql);
}
if (mysqlConnection.passwordExpire && !doExpire(mysqlConnection, sql, packetId)) {
MysqlResponseHandler.responseError(packetId, mysqlConnection.channel, ErrorCode.ER_PASSWORD_EXPIRE);
return;
}
executeSingleQuery(sql, packetId, mysqlConnection);
}

private boolean doExpire(MysqlConnection mysqlConnection, String sql, AtomicLong packetId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ public static void responseError(AtomicLong packetId,
ep.capabilities = MysqlServer.getServerCapabilities();
ep.errorCode = exception.getErrorCode();
ep.sqlState = exception.getSQLState();
ep.errorMessage = exception.getMessage();
if (exception.getMessage() == null) {
ep.errorMessage = "";
} else if (exception.getMessage().startsWith("Encountered")) {
ep.errorMessage = "You have an error in your SQL syntax";
} else {
ep.errorMessage = exception.getMessage();
}
ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();
ep.write(buffer);
channel.writeAndFlush(buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static final int getServerCapabilities() {
flag |= CapabilityFlags.CLIENT_SECURE_CONNECTION.getCode();
flag |= CapabilityFlags.CLIENT_SSL.getCode();
//upper
flag |= CapabilityFlags.CLIENT_MULTI_STATEMENTS.getCode();
//flag |= CapabilityFlags.CLIENT_MULTI_STATEMENTS.getCode();
flag |= CapabilityFlags.CLIENT_MULTI_RESULTS.getCode();
flag |= CapabilityFlags.CLIENT_PS_MULTI_RESULTS.getCode();
//flag |= CapabilityFlags.CLIENT_PLUGIN_AUTH.getCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ CreateUserFailed=Error 1396 (HY000): Operation CREATE USER failed for ''{0}''@''
DropUserFailed=Error 1396 (HY000): Operation DROP USER failed for ''{0}''@''{1}''
AlterUserFailed=Error 1396 (HY000): Operation ALTER USER failed for ''{0}''@''{1}''
NoMatchingRowForUser=ERROR 1133 (42000): Can't find any matching row in the user table
ParseSqlSyntaxError=ERROR 1064 (42000): You have an error in your SQL syntax

0 comments on commit 8dde3c4

Please sign in to comment.