mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
Support MySQL 'SELECT DATABASE()' query replacement
This commit is contained in:
parent
b4c2c4906e
commit
5ca3aef919
@ -48,6 +48,7 @@ namespace ErrorCodes
|
||||
static String selectEmptyReplacementQuery(const String & query);
|
||||
static String showTableStatusReplacementQuery(const String & query);
|
||||
static String killConnectionIdReplacementQuery(const String & query);
|
||||
static String selectDatabaseReplacementQuery(const String & query);
|
||||
|
||||
MySQLHandler::MySQLHandler(IServer & server_, const Poco::Net::StreamSocket & socket_,
|
||||
bool ssl_enabled, size_t connection_id_)
|
||||
@ -65,6 +66,7 @@ MySQLHandler::MySQLHandler(IServer & server_, const Poco::Net::StreamSocket & so
|
||||
replacements.emplace("KILL QUERY", killConnectionIdReplacementQuery);
|
||||
replacements.emplace("SHOW TABLE STATUS LIKE", showTableStatusReplacementQuery);
|
||||
replacements.emplace("SHOW VARIABLES", selectEmptyReplacementQuery);
|
||||
replacements.emplace("SELECT DATABASE()", selectDatabaseReplacementQuery);
|
||||
}
|
||||
|
||||
void MySQLHandler::run()
|
||||
@ -437,5 +439,14 @@ static String killConnectionIdReplacementQuery(const String & query)
|
||||
return query;
|
||||
}
|
||||
|
||||
/// Replace "SELECT DATABASE()" into "SELECT currentDatabase() AS `DATABASE()`".
|
||||
static String selectDatabaseReplacementQuery(const String & query)
|
||||
{
|
||||
const String prefix = "SELECT DATABASE()";
|
||||
if (query.size() > prefix.size())
|
||||
return query;
|
||||
else
|
||||
return ("SELECT currentDatabase() AS `DATABASE()`");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user