Skip to content

Commit ff75cdf

Browse files
Stop printing a trailing space after PUBLIC in GRANT and REVOKE (#2416)
1 parent c0054b7 commit ff75cdf

2 files changed

Lines changed: 18 additions & 27 deletions

File tree

src/ast/mod.rs

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7544,34 +7544,22 @@ pub struct Grantee {
75447544

75457545
impl fmt::Display for Grantee {
75467546
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7547-
match self.grantee_type {
7548-
GranteesType::Role => {
7549-
write!(f, "ROLE ")?;
7550-
}
7551-
GranteesType::Share => {
7552-
write!(f, "SHARE ")?;
7553-
}
7554-
GranteesType::User => {
7555-
write!(f, "USER ")?;
7556-
}
7557-
GranteesType::Group => {
7558-
write!(f, "GROUP ")?;
7559-
}
7560-
GranteesType::Public => {
7561-
write!(f, "PUBLIC ")?;
7562-
}
7563-
GranteesType::DatabaseRole => {
7564-
write!(f, "DATABASE ROLE ")?;
7565-
}
7566-
GranteesType::Application => {
7567-
write!(f, "APPLICATION ")?;
7568-
}
7569-
GranteesType::ApplicationRole => {
7570-
write!(f, "APPLICATION ROLE ")?;
7547+
let keyword = match self.grantee_type {
7548+
GranteesType::Role => "ROLE",
7549+
GranteesType::Share => "SHARE",
7550+
GranteesType::User => "USER",
7551+
GranteesType::Group => "GROUP",
7552+
GranteesType::Public => "PUBLIC",
7553+
GranteesType::DatabaseRole => "DATABASE ROLE",
7554+
GranteesType::Application => "APPLICATION",
7555+
GranteesType::ApplicationRole => "APPLICATION ROLE",
7556+
GranteesType::None => "",
7557+
};
7558+
f.write_str(keyword)?;
7559+
if let Some(name) = &self.name {
7560+
if !keyword.is_empty() {
7561+
f.write_str(" ")?;
75717562
}
7572-
GranteesType::None => (),
7573-
}
7574-
if let Some(ref name) = self.name {
75757563
name.fmt(f)?;
75767564
}
75777565
Ok(())

tests/sqlparser_common.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10272,6 +10272,9 @@ fn parse_grant() {
1027210272
verified_stmt("GRANT ROLE role1 TO ROLE role2");
1027310273
verified_stmt("GRANT ROLE role1 TO USER user");
1027410274
verified_stmt("GRANT CREATE SCHEMA ON DATABASE db1 TO ROLE role1");
10275+
// PUBLIC takes no name, so it must not trail a space. MsSql reserves it as
10276+
// an ordinary grantee name.
10277+
all_dialects_except(|d| d.is::<MsSqlDialect>()).verified_stmt("GRANT SELECT ON t TO PUBLIC");
1027510278
}
1027610279

1027710280
#[test]

0 commit comments

Comments
 (0)