<p dir="auto">hi, i discover a question today<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/12891899/70315431-87082980-1854-11ea-9866-342589663a32.png"><img src="https://user-images.githubusercontent.com/12891899/70315431-87082980-1854-11ea-9866-342589663a32.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/12891899/70315512-b6b73180-1854-11ea-842a-68e785ac14bc.png"><img src="https://user-images.githubusercontent.com/12891899/70315512-b6b73180-1854-11ea-842a-68e785ac14bc.png" alt="微信图片_20191206181539" style="max-width: 100%;"></a></p>
<p dir="auto">Suggestion: You need to add a judgment that result is not equal to null, and ignore result equal to null</p>
<h3 dir="auto">Which version of ShardingSphere did you use?</h3>
<p dir="auto">4.0.0-RC1</p>
<h3 dir="auto">Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?</h3>
<p dir="auto">sharding-proxy</p>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">I hope Navicat can connect sharding-proxy</p>
<h3 dir="auto">Actual behavior</h3>
<p dir="auto">Navicat connection failed ,report No database selected</p>
<h3 dir="auto">Reason analyze (If you can)</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/*
 * 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 &quot;License&quot;); 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 &quot;AS IS&quot; 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();
    }
}
"><pre class="notranslate"><code class="notranslate">/*
 * 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();
    }
}

</code></pre></div>
<p dir="auto">Throw in this method</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    @Override
    public BackendResponse execute() {
        if (null == backendConnection.getLogicSchema()) {
            return new ErrorResponse(new NoDatabaseSelectedException());
        }
        databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(backendConnection.getLogicSchema(), sql, backendConnection);
        return databaseCommunicationEngine.execute();
    }"><pre class="notranslate"><code class="notranslate">    @Override
    public BackendResponse execute() {
        if (null == backendConnection.getLogicSchema()) {
            return new ErrorResponse(new NoDatabaseSelectedException());
        }
        databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(backendConnection.getLogicSchema(), sql, backendConnection);
        return databaseCommunicationEngine.execute();
    }
</code></pre></div>
<h3 dir="auto">Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.</h3>
<p dir="auto">[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]<br>
[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<br>
[INFO ] 17:24:17.498 [ShardingSphere-Command-14] ShardingSphere-SQL - Rule Type: sharding<br>
[INFO ] 17:24:17.498 [ShardingSphere-Command-14] ShardingSphere-SQL - Logic SQL: SET NAMES utf8mb4<br>
[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))<br>
[INFO ] 17:24:17.498 [ShardingSphere-Command-14] ShardingSphere-SQL - Actual SQL: ds_0 ::: SET NAMES utf8mb4<br>
[INFO ] 17:24:21.656 [ShardingSphere-Command-15] ShardingSphere-SQL - Rule Type: sharding<br>
[INFO ] 17:24:21.656 [ShardingSphere-Command-15] ShardingSphere-SQL - Logic SQL: SHOW VARIABLES LIKE 'lower_case_%'; SHOW VARIABLES LIKE 'sql_mode'; SELECT COUNT(<em>) AS support_ndb FROM information_schema.ENGINES WHERE Engine = 'ndbcluster'<br>
[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))<br>
[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(</em>) AS support_ndb FROM information_schema.ENGINES WHERE Engine = 'ndbcluster'<br>
[INFO ] 17:24:22.773 [ShardingSphere-Command-0] ShardingSphere-SQL - Rule Type: sharding<br>
[INFO ] 17:24:22.774 [ShardingSphere-Command-0] ShardingSphere-SQL - Logic SQL: SHOW VARIABLES LIKE 'lower_case_%'<br>
[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))<br>
[INFO ] 17:24:22.774 [ShardingSphere-Command-0] ShardingSphere-SQL - Actual SQL: ds_0 ::: SHOW VARIABLES LIKE 'lower_case_%'<br>
[INFO ] 17:24:23.911 [ShardingSphere-Command-1] ShardingSphere-SQL - Rule Type: sharding<br>
[INFO ] 17:24:23.911 [ShardingSphere-Command-1] ShardingSphere-SQL - Logic SQL: SHOW VARIABLES LIKE 'sql_mode'<br>
[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))<br>
[INFO ] 17:24:23.911 [ShardingSphere-Command-1] ShardingSphere-SQL - Actual SQL: ds_0 ::: SHOW VARIABLES LIKE 'sql_mode'</p>
<h3 dir="auto">Example codes for reproduce this issue (such as a github link).</h3>
<p dir="auto">config-sharding.yaml</p>
<p dir="auto">schemaName: sharding_db</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="dataSources:
  ds_0:
#    局域网
#    url: jdbc:mysql://***/***?serverTimezone=Asia/Shanghai&amp;useUnicode=true&amp;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$-&gt;{1..9},ds_0.service_attendance_detail_2021_1$-&gt;{0..2}
      tableStrategy:
        inline:
          shardingColumn: course_date
          algorithmExpression: service_attendance_detail_2021_$-&gt;{course_date[5..6]} "><pre class="notranslate"><code class="notranslate">dataSources:
  ds_0:
#    局域网
#    url: jdbc:mysql://***/***?serverTimezone=Asia/Shanghai&amp;useUnicode=true&amp;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$-&gt;{1..9},ds_0.service_attendance_detail_2021_1$-&gt;{0..2}
      tableStrategy:
        inline:
          shardingColumn: course_date
          algorithmExpression: service_attendance_detail_2021_$-&gt;{course_date[5..6]} 
</code></pre></div>
<p dir="auto">server.yaml</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>