| 1 | #include <Parsers/ASTRoleList.h> |
| 2 | #include <Common/quoteString.h> |
| 3 | |
| 4 | |
| 5 | namespace DB |
| 6 | { |
| 7 | void ASTRoleList::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const |
| 8 | { |
| 9 | if (empty()) |
| 10 | { |
| 11 | settings.ostr << (settings.hilite ? IAST::hilite_keyword : "" ) << "NONE" << (settings.hilite ? IAST::hilite_none : "" ); |
| 12 | return; |
| 13 | } |
| 14 | |
| 15 | bool need_comma = false; |
| 16 | if (current_user) |
| 17 | { |
| 18 | if (std::exchange(need_comma, true)) |
| 19 | settings.ostr << ", " ; |
| 20 | settings.ostr << (settings.hilite ? IAST::hilite_keyword : "" ) << "CURRENT_USER" << (settings.hilite ? IAST::hilite_none : "" ); |
| 21 | } |
| 22 | |
| 23 | for (auto & role : roles) |
| 24 | { |
| 25 | if (std::exchange(need_comma, true)) |
| 26 | settings.ostr << ", " ; |
| 27 | settings.ostr << backQuoteIfNeed(role); |
| 28 | } |
| 29 | |
| 30 | if (all_roles) |
| 31 | { |
| 32 | if (std::exchange(need_comma, true)) |
| 33 | settings.ostr << ", " ; |
| 34 | settings.ostr << (settings.hilite ? IAST::hilite_keyword : "" ) << "ALL" << (settings.hilite ? IAST::hilite_none : "" ); |
| 35 | if (except_current_user || !except_roles.empty()) |
| 36 | { |
| 37 | settings.ostr << (settings.hilite ? IAST::hilite_keyword : "" ) << " EXCEPT " << (settings.hilite ? IAST::hilite_none : "" ); |
| 38 | need_comma = false; |
| 39 | |
| 40 | if (except_current_user) |
| 41 | { |
| 42 | if (std::exchange(need_comma, true)) |
| 43 | settings.ostr << ", " ; |
| 44 | settings.ostr << (settings.hilite ? IAST::hilite_keyword : "" ) << "CURRENT_USER" << (settings.hilite ? IAST::hilite_none : "" ); |
| 45 | } |
| 46 | |
| 47 | for (auto & except_role : except_roles) |
| 48 | { |
| 49 | if (std::exchange(need_comma, true)) |
| 50 | settings.ostr << ", " ; |
| 51 | settings.ostr << backQuoteIfNeed(except_role); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |