mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-24 18:50:49 +00:00
97f2a2213e
* Move some code outside dbms/src folder * Fix paths
65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
#include <Parsers/ASTCreateRoleQuery.h>
|
|
#include <Parsers/ASTSettingsProfileElement.h>
|
|
#include <Common/quoteString.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
namespace
|
|
{
|
|
void formatRenameTo(const String & new_name, const IAST::FormatSettings & settings)
|
|
{
|
|
settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << " RENAME TO " << (settings.hilite ? IAST::hilite_none : "")
|
|
<< quoteString(new_name);
|
|
}
|
|
|
|
void formatSettings(const ASTSettingsProfileElements & settings, const IAST::FormatSettings & format)
|
|
{
|
|
format.ostr << (format.hilite ? IAST::hilite_keyword : "") << " SETTINGS " << (format.hilite ? IAST::hilite_none : "");
|
|
settings.format(format);
|
|
}
|
|
}
|
|
|
|
|
|
String ASTCreateRoleQuery::getID(char) const
|
|
{
|
|
return "CreateRoleQuery";
|
|
}
|
|
|
|
|
|
ASTPtr ASTCreateRoleQuery::clone() const
|
|
{
|
|
return std::make_shared<ASTCreateRoleQuery>(*this);
|
|
}
|
|
|
|
|
|
void ASTCreateRoleQuery::formatImpl(const FormatSettings & format, FormatState &, FormatStateStacked) const
|
|
{
|
|
if (attach)
|
|
{
|
|
format.ostr << (format.hilite ? hilite_keyword : "") << "ATTACH ROLE" << (format.hilite ? hilite_none : "");
|
|
}
|
|
else
|
|
{
|
|
format.ostr << (format.hilite ? hilite_keyword : "") << (alter ? "ALTER ROLE" : "CREATE ROLE")
|
|
<< (format.hilite ? hilite_none : "");
|
|
}
|
|
|
|
if (if_exists)
|
|
format.ostr << (format.hilite ? hilite_keyword : "") << " IF EXISTS" << (format.hilite ? hilite_none : "");
|
|
else if (if_not_exists)
|
|
format.ostr << (format.hilite ? hilite_keyword : "") << " IF NOT EXISTS" << (format.hilite ? hilite_none : "");
|
|
else if (or_replace)
|
|
format.ostr << (format.hilite ? hilite_keyword : "") << " OR REPLACE" << (format.hilite ? hilite_none : "");
|
|
|
|
format.ostr << " " << backQuoteIfNeed(name);
|
|
|
|
if (!new_name.empty())
|
|
formatRenameTo(new_name, format);
|
|
|
|
if (settings && (!settings->empty() || alter))
|
|
formatSettings(*settings, format);
|
|
}
|
|
|
|
}
|