2012-06-18 06:19:13 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Parsers/IAST.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/** RENAME запрос
|
|
|
|
*/
|
|
|
|
class ASTRenameQuery : public IAST
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Table
|
|
|
|
{
|
|
|
|
String database;
|
|
|
|
String table;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Element
|
|
|
|
{
|
|
|
|
Table from;
|
|
|
|
Table to;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<Element> Elements;
|
|
|
|
Elements elements;
|
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
ASTRenameQuery() = default;
|
|
|
|
ASTRenameQuery(const StringRange range_) : IAST(range_) {}
|
2015-05-03 09:13:08 +00:00
|
|
|
|
2012-06-18 06:19:13 +00:00
|
|
|
/** Получить текст, который идентифицирует этот элемент. */
|
2014-12-17 15:26:24 +00:00
|
|
|
String getID() const override { return "Rename"; };
|
2012-06-18 06:19:13 +00:00
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
ASTPtr clone() const override { return new ASTRenameQuery(*this); }
|
2015-08-05 21:38:31 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << "RENAME TABLE " << (settings.hilite ? hilite_none : "");
|
|
|
|
|
|
|
|
for (ASTRenameQuery::Elements::const_iterator it = elements.begin(); it != elements.end(); ++it)
|
|
|
|
{
|
|
|
|
if (it != elements.begin())
|
|
|
|
settings.ostr << ", ";
|
|
|
|
|
|
|
|
settings.ostr << (!it->from.database.empty() ? backQuoteIfNeed(it->from.database) + "." : "") << backQuoteIfNeed(it->from.table)
|
|
|
|
<< (settings.hilite ? hilite_keyword : "") << " TO " << (settings.hilite ? hilite_none : "")
|
|
|
|
<< (!it->to.database.empty() ? backQuoteIfNeed(it->to.database) + "." : "") << backQuoteIfNeed(it->to.table);
|
|
|
|
}
|
|
|
|
}
|
2012-06-18 06:19:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|