Issue 1:
hi, i discover a question today

Suggestion: You need to add a judgment that result is not equal to null, and ignore result equal to null

Issue 2:
Which version of ShardingSphere did you use?

4.0.0-RC1

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

sharding-proxy

Expected behavior

I hope Navicat can connect sharding-proxy

Actual behavior

Navicat connection failed ,report No database selected

Reason analyze (If you can)

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.shardingproxy.backend.text.query;

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.shardingproxy.backend.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.shardingproxy.backend.communication.DatabaseCommunicationEngineFactory;
import org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.shardingproxy.backend.exception.NoDatabaseSelectedException;
import org.apache.shardingsphere.shardingproxy.backend.response.BackendResponse;
import org.apache.shardingsphere.shardingproxy.backend.response.error.ErrorResponse;
import org.apache.shardingsphere.shardingproxy.backend.response.query.QueryData;
import org.apache.shardingsphere.shardingproxy.backend.text.TextProtocolBackendHandler;

import java.sql.SQLException;

/**
* Backend handler with query.
*
* @author zhangliang
*/
@RequiredArgsConstructor
public final class QueryBackendHandler implements TextProtocolBackendHandler {

private final DatabaseCommunicationEngineFactory databaseCommunicationEngineFactory = DatabaseCommunicationEngineFactory.getInstance();

private final String sql;

private final BackendConnection backendConnection;

private DatabaseCommunicationEngine databaseCommunicationEngine;

@Override
public BackendResponse execute() {
if (null == backendConnection.getLogicSchema()) {
return new ErrorResponse(new NoDatabaseSelectedException());
}
databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(backendConnection.getLogicSchema(), sql, backendConnection);
return databaseCommunicationEngine.execute();
}

@Override
public boolean next() throws SQLException {
return databaseCommunicationEngine.next();
}

@Override
public QueryData getQueryData() throws SQLException {
return databaseCommunicationEngine.getQueryData();
}
}

Throw in this method

@Override
public BackendResponse execute() {
if (null == backendConnection.getLogicSchema()) {
return new ErrorResponse(new NoDatabaseSelectedException());
}
databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(backendConnection.getLogicSchema(), sql, backendConnection);
return databaseCommunicationEngine.execute();
}

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

[INFO ] 17:24:17.483 [nioEventLoopGroup-2-1] i.n.handler.logging.LoggingHandler - [id: 0xcd0eea40, L:/0:0:0:0:0:0:0:0:3307] READ: [id: 0x3dded63d, L:/127.0.0.1:3307 - R:/127.0.0.1:53670]

[INFO ] 17:24:17.486 [nioEventLoopGroup-2-1] i.n.handler.logging.LoggingHandler - [id: 0xcd0eea40, L:/0:0:0:0:0:0:0:0:3307] READ COMPLETE

[INFO ] 17:24:17.498 [ShardingSphere-Command-14] ShardingSphere-SQL - Rule Type: sharding

[INFO ] 17:24:17.498 [ShardingSphere-Command-14] ShardingSphere-SQL - Logic SQL: SET NAMES utf8mb4

[INFO ] 17:24:17.498 [ShardingSphere-Command-14] ShardingSphere-SQL - SQLStatement: DALStatement(super=AbstractSQLStatement(type=DAL, tables=Tables(tables=[]), routeConditions=Conditions(orCondition=OrCondition(andConditions=[])), encryptConditions=Conditions(orCondition=OrCondition(andConditions=[])), sqlTokens=[], parametersIndex=0, logicSQL=null))

[INFO ] 17:24:17.498 [ShardingSphere-Command-14] ShardingSphere-SQL - Actual SQL: ds_0 ::: SET NAMES utf8mb4

[INFO ] 17:24:21.656 [ShardingSphere-Command-15] ShardingSphere-SQL - Rule Type: sharding

[INFO ] 17:24:21.656 [ShardingSphere-Command-15] ShardingSphere-SQL - Logic SQL: SHOW VARIABLES LIKE 'lower_case_%'; SHOW VARIABLES LIKE 'sql_mode'; SELECT COUNT() AS support_ndb FROM information_schema.ENGINES WHERE Engine = 'ndbcluster'

[INFO ] 17:24:21.656 [ShardingSphere-Command-15] ShardingSphere-SQL - SQLStatement: DALStatement(super=AbstractSQLStatement(type=DAL, tables=Tables(tables=[]), routeConditions=Conditions(orCondition=OrCondition(andConditions=[])), encryptConditions=Conditions(orCondition=OrCondition(andConditions=[])), sqlTokens=[], parametersIndex=0, logicSQL=null))

[INFO ] 17:24:21.656 [ShardingSphere-Command-15] ShardingSphere-SQL - Actual SQL: ds_0 ::: SHOW VARIABLES LIKE 'lower_case_%'; SHOW VARIABLES LIKE 'sql_mode'; SELECT COUNT() AS support_ndb FROM information_schema.ENGINES WHERE Engine = 'ndbcluster'

[INFO ] 17:24:22.773 [ShardingSphere-Command-0] ShardingSphere-SQL - Rule Type: sharding

[INFO ] 17:24:22.774 [ShardingSphere-Command-0] ShardingSphere-SQL - Logic SQL: SHOW VARIABLES LIKE 'lower_case_%'

[INFO ] 17:24:22.774 [ShardingSphere-Command-0] ShardingSphere-SQL - SQLStatement: DALStatement(super=AbstractSQLStatement(type=DAL, tables=Tables(tables=[]), routeConditions=Conditions(orCondition=OrCondition(andConditions=[])), encryptConditions=Conditions(orCondition=OrCondition(andConditions=[])), sqlTokens=[], parametersIndex=0, logicSQL=null))

[INFO ] 17:24:22.774 [ShardingSphere-Command-0] ShardingSphere-SQL - Actual SQL: ds_0 ::: SHOW VARIABLES LIKE 'lower_case_%'

[INFO ] 17:24:23.911 [ShardingSphere-Command-1] ShardingSphere-SQL - Rule Type: sharding

[INFO ] 17:24:23.911 [ShardingSphere-Command-1] ShardingSphere-SQL - Logic SQL: SHOW VARIABLES LIKE 'sql_mode'

[INFO ] 17:24:23.911 [ShardingSphere-Command-1] ShardingSphere-SQL - SQLStatement: DALStatement(super=AbstractSQLStatement(type=DAL, tables=Tables(tables=[]), routeConditions=Conditions(orCondition=OrCondition(andConditions=[])), encryptConditions=Conditions(orCondition=OrCondition(andConditions=[])), sqlTokens=[], parametersIndex=0, logicSQL=null))

[INFO ] 17:24:23.911 [ShardingSphere-Command-1] ShardingSphere-SQL - Actual SQL: ds_0 ::: SHOW VARIABLES LIKE 'sql_mode'

Example codes for reproduce this issue (such as a github link).

config-sharding.yaml

schemaName: sharding_db

dataSources:
ds_0:
# 局域网
# url: jdbc:mysql://***/***?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8
username: ***
password: ***
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
maintenanceIntervalMilliseconds: 30000
shardingRule:
tables:
service_attendance_detail:
actualDataNodes: ds_0.service_attendance_detail_2021_0$->{1..9},ds_0.service_attendance_detail_2021_1$->{0..2}
tableStrategy:
inline:
shardingColumn: course_date
algorithmExpression: service_attendance_detail_2021_$->{course_date[5..6]}

server.yaml

authentication:
username: root
password: root
#
props:
max.connections.size.per.query: 1
acceptor.size: 16 # The default value is available processors count * 2.
executor.size: 16 # Infinite by default.
# proxy.frontend.flush.threshold: 128 # The default value is 128.
# # LOCAL: Proxy will run with LOCAL transaction.
# # XA: Proxy will run with XA transaction.
# # BASE: Proxy will run with B.A.S.E transaction.
# proxy.transaction.type: LOCAL
# proxy.opentracing.enabled: false
sql.show: true