2012-06-18 07:49:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-08-06 03:26:27 +00:00
|
|
|
#include <mysqlxx/Manip.h>
|
2012-06-18 07:49:19 +00:00
|
|
|
#include <DB/Parsers/IAST.h>
|
2013-02-20 13:14:12 +00:00
|
|
|
#include <DB/Parsers/ASTQueryWithOutput.h>
|
2012-06-18 07:49:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/** Запрос SHOW TABLES или SHOW DATABASES
|
|
|
|
*/
|
2013-02-20 13:14:12 +00:00
|
|
|
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_) {}
|
2015-08-06 03:26:27 +00:00
|
|
|
|
2012-06-18 07:49:19 +00:00
|
|
|
/** Получить текст, который идентифицирует этот элемент. */
|
2015-05-03 09:13:08 +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
|
2013-02-20 13:14:12 +00:00
|
|
|
{
|
|
|
|
ASTShowTablesQuery * res = new ASTShowTablesQuery(*this);
|
2014-12-17 15:26:24 +00:00
|
|
|
ASTPtr ptr{res};
|
|
|
|
|
2013-02-20 13:14:12 +00:00
|
|
|
res->children.clear();
|
2015-08-06 03:26:27 +00:00
|
|
|
|
2013-02-20 13:14:12 +00:00
|
|
|
if (format)
|
|
|
|
{
|
|
|
|
res->format = format->clone();
|
|
|
|
res->children.push_back(res->format);
|
|
|
|
}
|
2015-08-06 03:26:27 +00:00
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
return ptr;
|
2013-02-20 13:14:12 +00:00
|
|
|
}
|
2015-08-06 03:26:27 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void formatImpl(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format)
|
|
|
|
{
|
|
|
|
std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' ');
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << settings.nl_or_ws << indent_str << "FORMAT " << (settings.hilite ? hilite_none : "");
|
|
|
|
format->formatImpl(settings, state, frame);
|
|
|
|
}
|
|
|
|
}
|
2012-06-18 07:49:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|