1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor;
19
20 import lombok.Getter;
21 import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData;
22 import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultColumnMetaData;
23 import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultMetaData;
24 import org.apache.shardingsphere.infra.merge.result.MergedResult;
25 import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
26 import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
27 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
28 import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminQueryExecutor;
29
30 import java.sql.Types;
31 import java.util.Collections;
32
33
34
35
36 @Getter
37 public final class ShowCurrentDatabaseExecutor implements DatabaseAdminQueryExecutor {
38
39 public static final String FUNCTION_NAME = "DATABASE()";
40
41 private MergedResult mergedResult;
42
43 @Override
44 public void execute(final ConnectionSession connectionSession) {
45 mergedResult = new LocalDataMergedResult(Collections.singleton(new LocalDataQueryResultRow(connectionSession.getDatabaseName())));
46 }
47
48 @Override
49 public QueryResultMetaData getQueryResultMetaData() {
50 return new RawQueryResultMetaData(Collections.singletonList(new RawQueryResultColumnMetaData("SCHEMATA", FUNCTION_NAME, FUNCTION_NAME, Types.VARCHAR, "VARCHAR", 100, 0)));
51 }
52 }