2012-06-18 07:49:19 +00:00
|
|
|
#include <DB/Parsers/ASTLiteral.h>
|
|
|
|
#include <DB/Parsers/ASTIdentifier.h>
|
|
|
|
#include <DB/Parsers/ASTShowTablesQuery.h>
|
|
|
|
|
|
|
|
#include <DB/Parsers/CommonParsers.h>
|
|
|
|
#include <DB/Parsers/ParserShowTablesQuery.h>
|
|
|
|
#include <DB/Parsers/ExpressionElementParsers.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
bool ParserShowTablesQuery::parseImpl(Pos & pos, Pos end, ASTPtr & node, String & expected)
|
|
|
|
{
|
|
|
|
Pos begin = pos;
|
|
|
|
|
|
|
|
ParserWhiteSpaceOrComments ws;
|
|
|
|
ParserString s_show("SHOW", true, true);
|
|
|
|
ParserString s_tables("TABLES", true, true);
|
|
|
|
ParserString s_databases("DATABASES", true, true);
|
|
|
|
ParserString s_from("FROM", true, true);
|
2012-07-27 19:20:44 +00:00
|
|
|
ParserString s_like("LIKE", true, true);
|
2013-02-20 13:14:12 +00:00
|
|
|
ParserString s_format("FORMAT", true, true);
|
2012-06-18 07:49:19 +00:00
|
|
|
ParserStringLiteral like_p;
|
|
|
|
ParserIdentifier name_p;
|
|
|
|
|
2013-02-20 13:14:12 +00:00
|
|
|
ASTPtr like;
|
|
|
|
ASTPtr database;
|
|
|
|
ASTPtr format;
|
2012-06-18 07:49:19 +00:00
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (!s_show.ignore(pos, end, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (s_databases.ignore(pos, end))
|
|
|
|
{
|
|
|
|
ASTShowTablesQuery * query = new ASTShowTablesQuery(StringRange(begin, pos));
|
|
|
|
query->databases = true;
|
|
|
|
node = query;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!s_tables.ignore(pos, end, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (s_from.ignore(pos, end, expected))
|
|
|
|
{
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2013-02-20 13:14:12 +00:00
|
|
|
if (!name_p.parse(pos, end, database, expected))
|
2012-06-18 07:49:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (s_like.ignore(pos, end, expected))
|
|
|
|
{
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2013-02-20 13:14:12 +00:00
|
|
|
if (!like_p.parse(pos, end, like, expected))
|
2012-06-18 07:49:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
2013-02-20 13:14:12 +00:00
|
|
|
|
|
|
|
if (s_format.ignore(pos, end, expected))
|
|
|
|
{
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
ParserIdentifier format_p;
|
|
|
|
|
|
|
|
if (!format_p.parse(pos, end, format, expected))
|
|
|
|
return false;
|
|
|
|
dynamic_cast<ASTIdentifier &>(*format).kind = ASTIdentifier::Format;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
}
|
2012-06-18 07:49:19 +00:00
|
|
|
|
|
|
|
ASTShowTablesQuery * query = new ASTShowTablesQuery(StringRange(begin, pos));
|
|
|
|
node = query;
|
|
|
|
|
2013-02-20 13:14:12 +00:00
|
|
|
if (database)
|
|
|
|
query->from = dynamic_cast<ASTIdentifier &>(*database).name;
|
|
|
|
if (like)
|
|
|
|
query->like = safeGet<const String &>(dynamic_cast<ASTLiteral &>(*like).value);
|
|
|
|
if (format)
|
|
|
|
{
|
|
|
|
query->format = format;
|
|
|
|
query->children.push_back(format);
|
|
|
|
}
|
2012-06-18 07:49:19 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|