diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java index 4a001bba1f1b7..bb71b2da181e5 100644 --- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java +++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java @@ -63,13 +63,14 @@ public final class MySQLComStmtExecuteExecutor implements QueryCommandExecutor { private final ConnectionSession connectionSession; - private ProxyBackendHandler proxyBackendHandler; + private final ProxyBackendHandler proxyBackendHandler; @Getter private ResponseType responseType; - @Override - public Collection execute() throws SQLException { + public MySQLComStmtExecuteExecutor(final MySQLComStmtExecutePacket packet, final ConnectionSession connectionSession) throws SQLException { + this.packet = packet; + this.connectionSession = connectionSession; MySQLServerPreparedStatement preparedStatement = updateAndGetPreparedStatement(); List params = packet.readParameters(preparedStatement.getParameterTypes(), preparedStatement.getLongData().keySet(), preparedStatement.getParameterColumnDefinitionFlags()); preparedStatement.getLongData().forEach(params::set); @@ -81,8 +82,6 @@ public Collection execute() throws SQLException { ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(), true); connectionSession.setQueryContext(queryContext); proxyBackendHandler = ProxyBackendHandlerFactory.newInstance(TypedSPILoader.getService(DatabaseType.class, "MySQL"), queryContext, connectionSession, true); - ResponseHeader responseHeader = proxyBackendHandler.execute(); - return responseHeader instanceof QueryResponseHeader ? processQuery((QueryResponseHeader) responseHeader) : processUpdate((UpdateResponseHeader) responseHeader); } private MySQLServerPreparedStatement updateAndGetPreparedStatement() { @@ -94,6 +93,12 @@ private MySQLServerPreparedStatement updateAndGetPreparedStatement() { return result; } + @Override + public Collection execute() throws SQLException { + ResponseHeader responseHeader = proxyBackendHandler.execute(); + return responseHeader instanceof QueryResponseHeader ? processQuery((QueryResponseHeader) responseHeader) : processUpdate((UpdateResponseHeader) responseHeader); + } + private Collection processQuery(final QueryResponseHeader queryResponseHeader) { responseType = ResponseType.QUERY; int characterSet = connectionSession.getAttributeMap().attr(MySQLConstants.CHARACTER_SET_ATTRIBUTE_KEY).get().getId(); diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java index ca6153cc1f7e2..50f716e9c61ee 100644 --- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java +++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java @@ -59,10 +59,11 @@ public final class MySQLComFieldListPacketExecutor implements CommandExecutor { private final ConnectionSession connectionSession; - private DatabaseConnector databaseConnector; + private final DatabaseConnector databaseConnector; - @Override - public Collection execute() throws SQLException { + public MySQLComFieldListPacketExecutor(final MySQLComFieldListPacket packet, final ConnectionSession connectionSession) { + this.packet = packet; + this.connectionSession = connectionSession; String databaseName = connectionSession.getCurrentDatabaseName(); String sql = String.format(SQL, packet.getTable(), databaseName); MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts(); @@ -73,8 +74,12 @@ public Collection execute() throws SQLException { ProxyDatabaseConnectionManager databaseConnectionManager = connectionSession.getDatabaseConnectionManager(); QueryContext queryContext = new QueryContext(sqlStatementContext, sql, Collections.emptyList(), hintValueContext, connectionSession.getConnectionContext(), metaDataContexts.getMetaData()); databaseConnector = DatabaseConnectorFactory.getInstance().newInstance(queryContext, databaseConnectionManager, false); + } + + @Override + public Collection execute() throws SQLException { databaseConnector.execute(); - return createColumnDefinition41Packets(databaseName); + return createColumnDefinition41Packets(connectionSession.getCurrentDatabaseName()); } private Collection createColumnDefinition41Packets(final String databaseName) throws SQLException {