ClickHouse/dbms/include/DB/Parsers/ASTShowTablesQuery.h

59 lines
1.5 KiB
C++
Raw Normal View History

2012-06-18 07:49:19 +00:00
#pragma once
#include <mysqlxx/Manip.h>
2012-06-18 07:49:19 +00:00
#include <DB/Parsers/IAST.h>
#include <DB/Parsers/ASTQueryWithOutput.h>
2012-06-18 07:49:19 +00:00
namespace DB
{
/** Запрос SHOW TABLES или SHOW DATABASES
*/
class ASTShowTablesQuery : public ASTQueryWithOutput
2012-06-18 07:49:19 +00:00
{
public:
2014-12-17 15:26:24 +00:00
bool databases{false};
2012-06-18 07:49:19 +00:00
String from;
String like;
2014-12-17 15:26:24 +00:00
bool not_like{false};
2012-06-18 07:49:19 +00:00
2014-12-17 15:26:24 +00:00
ASTShowTablesQuery() = default;
ASTShowTablesQuery(const StringRange range_) : ASTQueryWithOutput(range_) {}
2012-06-18 07:49:19 +00:00
/** Получить текст, который идентифицирует этот элемент. */
String getID() const override { return "ShowTables"; };
2012-06-18 07:49:19 +00:00
2014-12-17 15:26:24 +00:00
ASTPtr clone() const override
{
auto res = std::make_shared<ASTShowTablesQuery>(*this);
res->children.clear();
cloneOutputOptions(*res);
return res;
}
protected:
void formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
{
if (databases)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW DATABASES" << (settings.hilite ? hilite_none : "");
}
else
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW TABLES" << (settings.hilite ? hilite_none : "");
if (!from.empty())
settings.ostr << (settings.hilite ? hilite_keyword : "") << " FROM " << (settings.hilite ? hilite_none : "")
<< backQuoteIfNeed(from);
if (!like.empty())
settings.ostr << (settings.hilite ? hilite_keyword : "") << " LIKE " << (settings.hilite ? hilite_none : "")
<< mysqlxx::quote << like;
}
}
2012-06-18 07:49:19 +00:00
};
}