2018-06-09 16:03:07 +00:00
|
|
|
#include <Parsers/ASTDropQuery.h>
|
2019-10-08 18:42:22 +00:00
|
|
|
#include <Common/quoteString.h>
|
2020-11-09 16:05:40 +00:00
|
|
|
#include <IO/Operators.h>
|
2018-06-09 16:03:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
2021-09-06 22:13:54 +00:00
|
|
|
return "DropQuery" + (delim + getDatabase()) + delim + getTable();
|
2018-06-09 16:03:07 +00:00
|
|
|
else if (kind == ASTDropQuery::Kind::Detach)
|
2021-09-06 22:13:54 +00:00
|
|
|
return "DetachQuery" + (delim + getDatabase()) + delim + getTable();
|
2018-06-09 16:03:07 +00:00
|
|
|
else if (kind == ASTDropQuery::Kind::Truncate)
|
2021-09-06 22:13:54 +00:00
|
|
|
return "TruncateQuery" + (delim + getDatabase()) + delim + getTable();
|
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);
|
2021-09-06 22:13:54 +00:00
|
|
|
cloneTableOptions(*res);
|
2018-06-09 16:03:07 +00:00
|
|
|
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 ";
|
|
|
|
|
2021-09-06 22:13:54 +00:00
|
|
|
|
2021-11-11 13:28:18 +00:00
|
|
|
if (!table && database)
|
2019-10-08 11:10:29 +00:00
|
|
|
settings.ostr << "DATABASE ";
|
2020-03-23 22:28:30 +00:00
|
|
|
else if (is_dictionary)
|
2019-10-08 11:10:29 +00:00
|
|
|
settings.ostr << "DICTIONARY ";
|
2020-03-23 22:28:30 +00:00
|
|
|
else if (is_view)
|
|
|
|
settings.ostr << "VIEW ";
|
|
|
|
else
|
|
|
|
settings.ostr << "TABLE ";
|
2018-06-09 16:03:07 +00:00
|
|
|
|
|
|
|
if (if_exists)
|
|
|
|
settings.ostr << "IF EXISTS ";
|
|
|
|
|
|
|
|
settings.ostr << (settings.hilite ? hilite_none : "");
|
|
|
|
|
2021-11-11 13:28:18 +00:00
|
|
|
if (!table && database)
|
2021-09-06 22:13:54 +00:00
|
|
|
settings.ostr << backQuoteIfNeed(getDatabase());
|
2018-06-09 16:03:07 +00:00
|
|
|
else
|
2021-11-11 13:28:18 +00:00
|
|
|
settings.ostr << (database ? backQuoteIfNeed(getDatabase()) + "." : "") << backQuoteIfNeed(getTable());
|
2018-06-09 16:03:07 +00:00
|
|
|
|
|
|
|
formatOnCluster(settings);
|
2020-03-20 00:07:52 +00:00
|
|
|
|
2020-11-30 17:52:32 +00:00
|
|
|
if (permanently)
|
|
|
|
settings.ostr << " PERMANENTLY";
|
|
|
|
|
2020-03-20 00:07:52 +00:00
|
|
|
if (no_delay)
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " NO DELAY" << (settings.hilite ? hilite_none : "");
|
2018-06-09 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|