From 6a4e478ec862cdb06d55806fd3f8d1adb172a6de Mon Sep 17 00:00:00 2001 From: MeteorSky Date: Sun, 19 Jan 2025 18:35:05 +0800 Subject: [PATCH] Check if used database is null or empty --- .../shardingsphere/infra/session/query/QueryContext.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java b/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java index aee2d8fe593cc..070a84e785631 100644 --- a/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java +++ b/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java @@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; +import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.NoDatabaseSelectedException; import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.UnknownDatabaseException; import org.apache.shardingsphere.infra.exception.generic.UnsupportedSQLOperationException; import org.apache.shardingsphere.infra.hint.HintValueContext; @@ -90,6 +91,8 @@ private Collection getCurrentDatabaseNames(final ConnectionContext conne * @return used database */ public ShardingSphereDatabase getUsedDatabase() { + ShardingSpherePreconditions.checkNotNull(usedDatabaseNames, NoDatabaseSelectedException::new); + ShardingSpherePreconditions.checkNotEmpty(usedDatabaseNames, NoDatabaseSelectedException::new); ShardingSpherePreconditions.checkState(usedDatabaseNames.size() <= 1, () -> new UnsupportedSQLOperationException(String.format("Can not support multiple logic databases [%s]", Joiner.on(", ").join(usedDatabaseNames)))); String databaseName = usedDatabaseNames.iterator().next();