ClickHouse/dbms/src/Parsers/ASTShowTablesQuery.h

57 lines
1.5 KiB
C++
Raw Normal View History

2012-06-18 07:49:19 +00:00
#pragma once
2017-04-16 05:40:17 +00:00
#include <iomanip>
#include <Parsers/IAST.h>
#include <Parsers/ASTQueryWithOutput.h>
2012-06-18 07:49:19 +00:00
namespace DB
{
2017-05-27 17:27:16 +00:00
/** Query SHOW TABLES or SHOW DATABASES
2012-06-18 07:49:19 +00:00
*/
class ASTShowTablesQuery : public ASTQueryWithOutput
2012-06-18 07:49:19 +00:00
{
public:
bool databases{false};
bool temporary{false};
String from;
String like;
bool not_like{false};
2012-06-18 07:49:19 +00:00
2017-05-27 17:27:16 +00:00
/** Get the text that identifies this element. */
String getID(char) const override { return "ShowTables"; }
2012-06-18 07:49:19 +00:00
ASTPtr clone() const override
{
auto res = std::make_shared<ASTShowTablesQuery>(*this);
res->children.clear();
cloneOutputOptions(*res);
return res;
}
protected:
2017-12-01 18:36:55 +00:00
void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) 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 : "")
2017-04-16 05:40:17 +00:00
<< std::quoted(like, '\'');
}
}
2012-06-18 07:49:19 +00:00
};
}