2019-12-01 22:01:05 +00:00
|
|
|
#include <Parsers/ASTShowCreateAccessEntityQuery.h>
|
|
|
|
#include <Common/quoteString.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using Kind = ASTShowCreateAccessEntityQuery::Kind;
|
|
|
|
|
|
|
|
const char * kindToKeyword(Kind kind)
|
|
|
|
{
|
|
|
|
switch (kind)
|
|
|
|
{
|
2020-02-04 22:37:04 +00:00
|
|
|
case Kind::USER: return "USER";
|
2019-12-01 22:01:05 +00:00
|
|
|
case Kind::QUOTA: return "QUOTA";
|
2019-11-29 17:22:56 +00:00
|
|
|
case Kind::ROW_POLICY: return "POLICY";
|
2019-12-01 22:01:05 +00:00
|
|
|
}
|
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ASTShowCreateAccessEntityQuery::ASTShowCreateAccessEntityQuery(Kind kind_)
|
|
|
|
: kind(kind_), keyword(kindToKeyword(kind_))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String ASTShowCreateAccessEntityQuery::getID(char) const
|
|
|
|
{
|
|
|
|
return String("SHOW CREATE ") + keyword + " query";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ASTPtr ASTShowCreateAccessEntityQuery::clone() const
|
|
|
|
{
|
|
|
|
return std::make_shared<ASTShowCreateAccessEntityQuery>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ASTShowCreateAccessEntityQuery::formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< "SHOW CREATE " << keyword
|
|
|
|
<< (settings.hilite ? hilite_none : "");
|
|
|
|
|
2020-02-04 22:37:04 +00:00
|
|
|
if ((kind == Kind::USER) && current_user)
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " CURRENT_USER" << (settings.hilite ? hilite_none : "");
|
|
|
|
else if ((kind == Kind::QUOTA) && current_quota)
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " CURRENT" << (settings.hilite ? hilite_none : "");
|
|
|
|
else if (kind == Kind::ROW_POLICY)
|
2019-11-29 17:22:56 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2019-12-01 22:01:05 +00:00
|
|
|
else
|
|
|
|
settings.ostr << " " << backQuoteIfNeed(name);
|
|
|
|
}
|
|
|
|
}
|