Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 15 additions & 27 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7544,34 +7544,22 @@ pub struct Grantee {

impl fmt::Display for Grantee {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.grantee_type {
GranteesType::Role => {
write!(f, "ROLE ")?;
}
GranteesType::Share => {
write!(f, "SHARE ")?;
}
GranteesType::User => {
write!(f, "USER ")?;
}
GranteesType::Group => {
write!(f, "GROUP ")?;
}
GranteesType::Public => {
write!(f, "PUBLIC ")?;
}
GranteesType::DatabaseRole => {
write!(f, "DATABASE ROLE ")?;
}
GranteesType::Application => {
write!(f, "APPLICATION ")?;
}
GranteesType::ApplicationRole => {
write!(f, "APPLICATION ROLE ")?;
let keyword = match self.grantee_type {
GranteesType::Role => "ROLE",
GranteesType::Share => "SHARE",
GranteesType::User => "USER",
GranteesType::Group => "GROUP",
GranteesType::Public => "PUBLIC",
GranteesType::DatabaseRole => "DATABASE ROLE",
GranteesType::Application => "APPLICATION",
GranteesType::ApplicationRole => "APPLICATION ROLE",
GranteesType::None => "",
};
f.write_str(keyword)?;
if let Some(name) = &self.name {
if !keyword.is_empty() {
f.write_str(" ")?;
}
GranteesType::None => (),
}
if let Some(ref name) = self.name {
name.fmt(f)?;
}
Ok(())
Expand Down
3 changes: 3 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10061,6 +10061,9 @@ fn parse_grant() {
verified_stmt("GRANT ROLE role1 TO ROLE role2");
verified_stmt("GRANT ROLE role1 TO USER user");
verified_stmt("GRANT CREATE SCHEMA ON DATABASE db1 TO ROLE role1");
// PUBLIC takes no name, so it must not trail a space. MsSql reserves it as
// an ordinary grantee name.
all_dialects_except(|d| d.is::<MsSqlDialect>()).verified_stmt("GRANT SELECT ON t TO PUBLIC");
}

#[test]
Expand Down
Loading