mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-02 20:42:04 +00:00
ee37f551a2
* make interpreter factory an instance * add registerInterpreter * register interpreters individually * try wire everything up * fix style * fix test
30 lines
831 B
C++
30 lines
831 B
C++
#include <Parsers/ASTUseQuery.h>
|
|
#include <Interpreters/Context.h>
|
|
#include <Interpreters/InterpreterFactory.h>
|
|
#include <Interpreters/InterpreterUseQuery.h>
|
|
#include <Access/Common/AccessFlags.h>
|
|
#include <Common/typeid_cast.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
BlockIO InterpreterUseQuery::execute()
|
|
{
|
|
const String & new_database = query_ptr->as<ASTUseQuery &>().getDatabase();
|
|
getContext()->checkAccess(AccessType::SHOW_DATABASES, new_database);
|
|
getContext()->getSessionContext()->setCurrentDatabase(new_database);
|
|
return {};
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
}
|