@@ -569,7 +569,8 @@ private static int executeQuery(CliContext ctx, IoTDBConnection connection, Stri
569
569
ZoneId zoneId = ZoneId .of (connection .getTimeZone ());
570
570
statement .setFetchSize (fetchSize );
571
571
boolean hasResultSet = statement .execute (cmd .trim ());
572
- updateUsingDatabaseIfNecessary (connection .getParams ().getDb ().orElse (null ));
572
+ updateSqlDialectAndUsingDatabase (
573
+ connection .getParams ().getSqlDialect (), connection .getParams ().getDb ().orElse (null ));
573
574
if (hasResultSet ) {
574
575
// print the result
575
576
try (ResultSet resultSet = statement .getResultSet ()) {
@@ -890,13 +891,18 @@ static boolean processCommand(CliContext ctx, String s, IoTDBConnection connecti
890
891
return true ;
891
892
}
892
893
893
- private static void updateUsingDatabaseIfNecessary (String database ) {
894
- if (!Objects .equals (usingDatabase , database )) {
895
- usingDatabase = database ;
894
+ private static void updateSqlDialectAndUsingDatabase (
895
+ String sqlDialectOfConnection , String databaseOfConnection ) {
896
+ boolean needUpdateCliPrefix =
897
+ !Objects .equals (sqlDialect , sqlDialectOfConnection )
898
+ || !Objects .equals (usingDatabase , databaseOfConnection );
899
+ sqlDialect = sqlDialectOfConnection ;
900
+ usingDatabase = databaseOfConnection ;
901
+ if (needUpdateCliPrefix ) {
902
+ cliPrefix = IOTDB ;
896
903
if (sqlDialect != null && Model .TABLE .name ().equals (sqlDialect .toUpperCase ())) {
897
- cliPrefix = IOTDB ;
898
- if (database != null ) {
899
- cliPrefix += ":" + database ;
904
+ if (databaseOfConnection != null ) {
905
+ cliPrefix += ":" + databaseOfConnection ;
900
906
}
901
907
}
902
908
}
0 commit comments