2012-07-12 19:49:22 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Parsers/IParserBase.h>
|
|
|
|
#include <DB/Parsers/ExpressionElementParsers.h>
|
|
|
|
#include <DB/Parsers/CommonParsers.h>
|
|
|
|
#include <DB/Parsers/ASTIdentifier.h>
|
|
|
|
#include <DB/Parsers/ASTUseQuery.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Запрос USE db
|
|
|
|
*/
|
|
|
|
class ParserUseQuery : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2014-03-10 12:25:37 +00:00
|
|
|
const char * getName() const { return "USE query"; }
|
2015-04-11 03:10:23 +00:00
|
|
|
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
|
2012-07-12 19:49:22 +00:00
|
|
|
{
|
|
|
|
Pos begin = pos;
|
|
|
|
|
|
|
|
ParserWhiteSpaceOrComments ws;
|
|
|
|
ParserString s_use("USE", true, true);
|
|
|
|
ParserIdentifier name_p;
|
|
|
|
|
|
|
|
ASTPtr database;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
if (!s_use.ignore(pos, end, max_parsed_pos, expected))
|
2012-07-12 19:49:22 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
if (!name_p.parse(pos, end, database, max_parsed_pos, expected))
|
2012-07-12 19:49:22 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2016-05-28 15:42:22 +00:00
|
|
|
auto query = std::make_shared<ASTUseQuery>(StringRange(begin, pos));
|
2014-06-26 00:58:14 +00:00
|
|
|
query->database = typeid_cast<ASTIdentifier &>(*database).name;
|
2016-05-28 15:42:22 +00:00
|
|
|
node = query;
|
2012-07-12 19:49:22 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|