2018-06-09 16:03:07 +00:00
|
|
|
#include <Parsers/ASTDropQuery.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int SYNTAX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-07 12:34:40 +00:00
|
|
|
String ASTDropQuery::getID(char delim) const
|
2018-06-09 16:03:07 +00:00
|
|
|
{
|
|
|
|
if (kind == ASTDropQuery::Kind::Drop)
|
2018-12-07 12:34:40 +00:00
|
|
|
return "DropQuery" + (delim + database) + delim + table;
|
2018-06-09 16:03:07 +00:00
|
|
|
else if (kind == ASTDropQuery::Kind::Detach)
|
2018-12-07 12:34:40 +00:00
|
|
|
return "DetachQuery" + (delim + database) + delim + table;
|
2018-06-09 16:03:07 +00:00
|
|
|
else if (kind == ASTDropQuery::Kind::Truncate)
|
2018-12-07 12:34:40 +00:00
|
|
|
return "TruncateQuery" + (delim + database) + delim + table;
|
2018-06-09 16:03:07 +00:00
|
|
|
else
|
|
|
|
throw Exception("Not supported kind of drop query.", ErrorCodes::SYNTAX_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
ASTPtr ASTDropQuery::clone() const
|
|
|
|
{
|
|
|
|
auto res = std::make_shared<ASTDropQuery>(*this);
|
|
|
|
cloneOutputOptions(*res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTDropQuery::formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "");
|
|
|
|
if (kind == ASTDropQuery::Kind::Drop)
|
|
|
|
settings.ostr << "DROP ";
|
|
|
|
else if (kind == ASTDropQuery::Kind::Detach)
|
|
|
|
settings.ostr << "DETACH ";
|
|
|
|
else if (kind == ASTDropQuery::Kind::Truncate)
|
|
|
|
settings.ostr << "TRUNCATE ";
|
|
|
|
else
|
|
|
|
throw Exception("Not supported kind of drop query.", ErrorCodes::SYNTAX_ERROR);
|
|
|
|
|
2018-07-16 03:34:05 +00:00
|
|
|
if (temporary)
|
|
|
|
settings.ostr << "TEMPORARY ";
|
|
|
|
|
2018-06-09 16:03:07 +00:00
|
|
|
settings.ostr << ((table.empty() && !database.empty()) ? "DATABASE " : "TABLE ");
|
|
|
|
|
|
|
|
if (if_exists)
|
|
|
|
settings.ostr << "IF EXISTS ";
|
|
|
|
|
|
|
|
settings.ostr << (settings.hilite ? hilite_none : "");
|
|
|
|
|
|
|
|
if (table.empty() && !database.empty())
|
|
|
|
settings.ostr << backQuoteIfNeed(database);
|
|
|
|
else
|
|
|
|
settings.ostr << (!database.empty() ? backQuoteIfNeed(database) + "." : "") << backQuoteIfNeed(table);
|
|
|
|
|
|
|
|
formatOnCluster(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|