mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
97f2a2213e
* Move some code outside dbms/src folder * Fix paths
76 lines
2.3 KiB
C++
76 lines
2.3 KiB
C++
#include <Parsers/ASTExtendedRoleSet.h>
|
|
#include <Common/quoteString.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
namespace
|
|
{
|
|
void formatRoleNameOrID(const String & str, bool is_id, const IAST::FormatSettings & settings)
|
|
{
|
|
if (is_id)
|
|
{
|
|
settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << "ID" << (settings.hilite ? IAST::hilite_none : "") << "("
|
|
<< quoteString(str) << ")";
|
|
}
|
|
else
|
|
{
|
|
settings.ostr << backQuoteIfNeed(str);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ASTExtendedRoleSet::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
|
|
{
|
|
if (empty())
|
|
{
|
|
settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << "NONE" << (settings.hilite ? IAST::hilite_none : "");
|
|
return;
|
|
}
|
|
|
|
bool need_comma = false;
|
|
if (all)
|
|
{
|
|
if (std::exchange(need_comma, true))
|
|
settings.ostr << ", ";
|
|
settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << "ALL" << (settings.hilite ? IAST::hilite_none : "");
|
|
}
|
|
else
|
|
{
|
|
for (auto & role : names)
|
|
{
|
|
if (std::exchange(need_comma, true))
|
|
settings.ostr << ", ";
|
|
formatRoleNameOrID(role, id_mode, settings);
|
|
}
|
|
|
|
if (current_user)
|
|
{
|
|
if (std::exchange(need_comma, true))
|
|
settings.ostr << ", ";
|
|
settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << "CURRENT_USER" << (settings.hilite ? IAST::hilite_none : "");
|
|
}
|
|
}
|
|
|
|
if (except_current_user || !except_names.empty())
|
|
{
|
|
settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << " EXCEPT " << (settings.hilite ? IAST::hilite_none : "");
|
|
need_comma = false;
|
|
|
|
for (auto & except_role : except_names)
|
|
{
|
|
if (std::exchange(need_comma, true))
|
|
settings.ostr << ", ";
|
|
formatRoleNameOrID(except_role, id_mode, settings);
|
|
}
|
|
|
|
if (except_current_user)
|
|
{
|
|
if (std::exchange(need_comma, true))
|
|
settings.ostr << ", ";
|
|
settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << "CURRENT_USER" << (settings.hilite ? IAST::hilite_none : "");
|
|
}
|
|
}
|
|
}
|
|
}
|