2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTUseQuery.h>
|
|
|
|
#include <Interpreters/Context.h>
|
2024-01-09 06:33:48 +00:00
|
|
|
#include <Interpreters/InterpreterFactory.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/InterpreterUseQuery.h>
|
2021-10-31 08:51:20 +00:00
|
|
|
#include <Access/Common/AccessFlags.h>
|
2017-07-13 20:58:19 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2016-12-12 07:24:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-12-12 07:27:47 +00:00
|
|
|
BlockIO InterpreterUseQuery::execute()
|
2016-12-12 07:24:56 +00:00
|
|
|
{
|
2023-08-15 18:37:39 +00:00
|
|
|
const String & new_database = query_ptr->as<ASTUseQuery &>().getDatabase();
|
2021-04-10 23:33:54 +00:00
|
|
|
getContext()->checkAccess(AccessType::SHOW_DATABASES, new_database);
|
|
|
|
getContext()->getSessionContext()->setCurrentDatabase(new_database);
|
2016-12-12 07:24:56 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2024-01-09 06:33:48 +00:00
|
|
|
void registerInterpreterUseQuery(InterpreterFactory & factory)
|
|
|
|
{
|
|
|
|
auto create_fn = [] (const InterpreterFactory::Arguments & args)
|
|
|
|
{
|
|
|
|
return std::make_unique<InterpreterUseQuery>(args.query, args.context);
|
|
|
|
};
|
|
|
|
factory.registerInterpreter("InterpreterUseQuery", create_fn);
|
|
|
|
}
|
|
|
|
|
2016-12-12 07:24:56 +00:00
|
|
|
}
|