2019-12-01 22:01:05 +00:00
|
|
|
#include <Parsers/ASTDropAccessEntityQuery.h>
|
|
|
|
#include <Common/quoteString.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using Kind = ASTDropAccessEntityQuery::Kind;
|
|
|
|
|
2020-03-18 14:11:44 +00:00
|
|
|
const char * getKeyword(Kind kind)
|
2019-12-01 22:01:05 +00:00
|
|
|
{
|
|
|
|
switch (kind)
|
|
|
|
{
|
2020-02-04 22:37:04 +00:00
|
|
|
case Kind::USER: return "USER";
|
2020-02-17 02:59:56 +00:00
|
|
|
case Kind::ROLE: return "ROLE";
|
2019-12-01 22:01:05 +00:00
|
|
|
case Kind::QUOTA: return "QUOTA";
|
2020-03-18 14:11:44 +00:00
|
|
|
case Kind::ROW_POLICY: return "ROW POLICY";
|
|
|
|
case Kind::SETTINGS_PROFILE: return "SETTINGS PROFILE";
|
2019-12-01 22:01:05 +00:00
|
|
|
}
|
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ASTDropAccessEntityQuery::ASTDropAccessEntityQuery(Kind kind_)
|
2020-03-18 14:11:44 +00:00
|
|
|
: kind(kind_)
|
2019-12-01 22:01:05 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String ASTDropAccessEntityQuery::getID(char) const
|
|
|
|
{
|
2020-03-18 14:11:44 +00:00
|
|
|
return String("DROP ") + getKeyword(kind) + " query";
|
2019-12-01 22:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ASTPtr ASTDropAccessEntityQuery::clone() const
|
|
|
|
{
|
|
|
|
return std::make_shared<ASTDropAccessEntityQuery>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ASTDropAccessEntityQuery::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "")
|
2020-03-18 14:11:44 +00:00
|
|
|
<< "DROP " << getKeyword(kind)
|
2019-12-01 22:01:05 +00:00
|
|
|
<< (if_exists ? " IF EXISTS" : "")
|
|
|
|
<< (settings.hilite ? hilite_none : "");
|
|
|
|
|
2019-11-29 17:22:56 +00:00
|
|
|
if (kind == Kind::ROW_POLICY)
|
2019-12-01 22:01:05 +00:00
|
|
|
{
|
2019-11-29 17:22:56 +00:00
|
|
|
bool need_comma = false;
|
|
|
|
for (const auto & row_policy_name : row_policies_names)
|
|
|
|
{
|
|
|
|
if (need_comma)
|
|
|
|
settings.ostr << ',';
|
|
|
|
need_comma = true;
|
|
|
|
const String & database = row_policy_name.database;
|
|
|
|
const String & table_name = row_policy_name.table_name;
|
|
|
|
const String & policy_name = row_policy_name.policy_name;
|
|
|
|
settings.ostr << ' ' << backQuoteIfNeed(policy_name) << (settings.hilite ? hilite_keyword : "") << " ON "
|
|
|
|
<< (settings.hilite ? hilite_none : "") << (database.empty() ? String{} : backQuoteIfNeed(database) + ".")
|
|
|
|
<< backQuoteIfNeed(table_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool need_comma = false;
|
|
|
|
for (const auto & name : names)
|
|
|
|
{
|
|
|
|
if (need_comma)
|
|
|
|
settings.ostr << ',';
|
|
|
|
need_comma = true;
|
|
|
|
settings.ostr << ' ' << backQuoteIfNeed(name);
|
|
|
|
}
|
2019-12-01 22:01:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|