2020-05-07 02:45:27 +00:00
|
|
|
#include <Parsers/ASTShowAccessEntitiesQuery.h>
|
|
|
|
#include <Common/quoteString.h>
|
2020-11-09 16:05:40 +00:00
|
|
|
#include <IO/Operators.h>
|
2020-05-07 02:45:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-06-06 07:21:02 +00:00
|
|
|
using EntityTypeInfo = IAccessEntity::TypeInfo;
|
2020-05-07 02:45:27 +00:00
|
|
|
|
|
|
|
|
2020-06-06 07:21:02 +00:00
|
|
|
String ASTShowAccessEntitiesQuery::getKeyword() const
|
2020-05-12 20:31:30 +00:00
|
|
|
{
|
2020-06-06 07:21:02 +00:00
|
|
|
if (current_quota)
|
|
|
|
return "CURRENT QUOTA";
|
|
|
|
if (current_roles)
|
|
|
|
return "CURRENT ROLES";
|
|
|
|
if (enabled_roles)
|
|
|
|
return "ENABLED ROLES";
|
|
|
|
return EntityTypeInfo::get(type).plural_name;
|
2020-05-12 20:31:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-07 02:45:27 +00:00
|
|
|
String ASTShowAccessEntitiesQuery::getID(char) const
|
|
|
|
{
|
2020-06-06 07:21:02 +00:00
|
|
|
return "SHOW " + String(getKeyword()) + " query";
|
2020-05-07 02:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTShowAccessEntitiesQuery::formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
|
|
|
|
{
|
2020-06-06 07:21:02 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW " << getKeyword() << (settings.hilite ? hilite_none : "");
|
|
|
|
|
|
|
|
if (!short_name.empty())
|
|
|
|
settings.ostr << " " << backQuoteIfNeed(short_name);
|
2020-05-07 02:45:27 +00:00
|
|
|
|
2020-06-06 07:21:02 +00:00
|
|
|
if (database_and_table_name)
|
2020-05-07 02:45:27 +00:00
|
|
|
{
|
2020-06-06 07:21:02 +00:00
|
|
|
const String & database = database_and_table_name->first;
|
|
|
|
const String & table_name = database_and_table_name->second;
|
2020-05-07 02:45:27 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " ON " << (settings.hilite ? hilite_none : "");
|
2020-06-06 07:21:02 +00:00
|
|
|
settings.ostr << (database.empty() ? "" : backQuoteIfNeed(database) + ".");
|
|
|
|
settings.ostr << (table_name.empty() ? "*" : backQuoteIfNeed(table_name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-26 22:37:00 +00:00
|
|
|
void ASTShowAccessEntitiesQuery::replaceEmptyDatabase(const String & current_database)
|
2020-06-06 07:21:02 +00:00
|
|
|
{
|
|
|
|
if (database_and_table_name)
|
|
|
|
{
|
|
|
|
String & database = database_and_table_name->first;
|
|
|
|
if (database.empty())
|
|
|
|
database = current_database;
|
2020-05-07 02:45:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|