2020-05-30 20:10:45 +00:00
|
|
|
#include <Parsers/ASTRolesOrUsersSet.h>
|
2019-12-01 22:01:05 +00:00
|
|
|
#include <Common/quoteString.h>
|
2020-11-09 16:05:40 +00:00
|
|
|
#include <IO/Operators.h>
|
2019-12-01 22:01:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-02-21 19:27:12 +00:00
|
|
|
namespace
|
|
|
|
{
|
2021-02-26 22:37:00 +00:00
|
|
|
void formatNameOrID(const String & str, bool is_id, const IAST::FormatSettings & settings)
|
2020-02-21 19:27:12 +00:00
|
|
|
{
|
|
|
|
if (is_id)
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << "ID" << (settings.hilite ? IAST::hilite_none : "") << "("
|
|
|
|
<< quoteString(str) << ")";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
settings.ostr << backQuoteIfNeed(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 20:10:45 +00:00
|
|
|
void ASTRolesOrUsersSet::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
|
2019-12-01 22:01:05 +00:00
|
|
|
{
|
|
|
|
if (empty())
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << "NONE" << (settings.hilite ? IAST::hilite_none : "");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool need_comma = false;
|
2021-02-26 22:37:00 +00:00
|
|
|
|
2020-02-10 15:24:33 +00:00
|
|
|
if (all)
|
2019-12-01 22:01:05 +00:00
|
|
|
{
|
|
|
|
if (std::exchange(need_comma, true))
|
|
|
|
settings.ostr << ", ";
|
2021-03-11 13:44:00 +00:00
|
|
|
settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << (use_keyword_any ? "ANY" : "ALL")
|
|
|
|
<< (settings.hilite ? IAST::hilite_none : "");
|
2019-12-01 22:01:05 +00:00
|
|
|
}
|
2020-02-10 15:24:33 +00:00
|
|
|
else
|
2019-12-01 22:01:05 +00:00
|
|
|
{
|
2021-02-26 22:37:00 +00:00
|
|
|
for (const auto & name : names)
|
2020-02-10 15:24:33 +00:00
|
|
|
{
|
|
|
|
if (std::exchange(need_comma, true))
|
|
|
|
settings.ostr << ", ";
|
2021-02-26 22:37:00 +00:00
|
|
|
formatNameOrID(name, id_mode, settings);
|
2020-02-10 15:24:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 : "");
|
|
|
|
}
|
2019-12-01 22:01:05 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 15:24:33 +00:00
|
|
|
if (except_current_user || !except_names.empty())
|
2019-12-01 22:01:05 +00:00
|
|
|
{
|
2020-02-10 15:24:33 +00:00
|
|
|
settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << " EXCEPT " << (settings.hilite ? IAST::hilite_none : "");
|
|
|
|
need_comma = false;
|
2019-12-01 22:01:05 +00:00
|
|
|
|
2021-02-26 22:37:00 +00:00
|
|
|
for (const auto & name : except_names)
|
2020-02-10 15:24:33 +00:00
|
|
|
{
|
|
|
|
if (std::exchange(need_comma, true))
|
|
|
|
settings.ostr << ", ";
|
2021-02-26 22:37:00 +00:00
|
|
|
formatNameOrID(name, id_mode, settings);
|
2020-02-10 15:24:33 +00:00
|
|
|
}
|
2019-12-01 22:01:05 +00:00
|
|
|
|
2020-02-10 15:24:33 +00:00
|
|
|
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 : "");
|
2019-12-01 22:01:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-05 23:03:20 +00:00
|
|
|
|
|
|
|
|
2021-02-26 22:37:00 +00:00
|
|
|
void ASTRolesOrUsersSet::replaceCurrentUserTag(const String & current_user_name)
|
2020-04-05 23:03:20 +00:00
|
|
|
{
|
|
|
|
if (current_user)
|
|
|
|
{
|
|
|
|
names.push_back(current_user_name);
|
|
|
|
current_user = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (except_current_user)
|
|
|
|
{
|
|
|
|
except_names.push_back(current_user_name);
|
|
|
|
except_current_user = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-01 22:01:05 +00:00
|
|
|
}
|