Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MySQL parsing of GRANT, REVOKE, and CREATE VIEW #1538

Merged
merged 22 commits into from
Jan 9, 2025
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
abd971d
Tokenize at signs separately from subsequent strings
mvzink Nov 19, 2024
9dc0d9e
Fix parsing GRANT/REVOKE for MySQL
mvzink Nov 20, 2024
64669ed
Parse MySQL CREATE VIEW parameters
mvzink Nov 20, 2024
69bb0d8
Fix lint error and no-std build
mvzink Nov 20, 2024
797c510
Add more test cases for create view
mvzink Nov 27, 2024
c896e10
Use generic names for optional `CREATE VIEW` params
mvzink Nov 27, 2024
935777b
Return errors instead of panicking when expect_one_keyword returns so…
mvzink Nov 27, 2024
99bf3f6
Add dialect support toggle for MySQL grantee syntax
mvzink Nov 27, 2024
3091653
Refactor parsing revoke cascade/restrict option to reuse truncate code
mvzink Nov 27, 2024
50506c4
Fix a doc comment about BigQuery identifiers
mvzink Nov 27, 2024
93a4b03
Merge branch 'main' into mysql-users
mvzink Nov 28, 2024
3fc2164
Accommodate new span field on ident for grantees and wildcards
mvzink Nov 28, 2024
f6b2a6a
Merge branch 'main' into mysql-users
mvzink Dec 12, 2024
4aebd01
Add comment about breaking on quotes in @ tokenization
mvzink Dec 12, 2024
9042222
Use destructuring to write create view params
mvzink Dec 12, 2024
1423d9e
Add tests for other quote styles
mvzink Dec 12, 2024
888773d
Merge branch 'main' into mysql-users
mvzink Dec 20, 2024
126b7b4
Merge branch 'main' into mysql-users
mvzink Dec 23, 2024
ed3e591
Address comments about dialect switching
mvzink Dec 24, 2024
7f1ff61
Merge branch 'main' into mysql-users
mvzink Jan 2, 2025
d052db1
Merge branch 'main' into mysql-users
mvzink Jan 8, 2025
c7f85ea
Avoid unnecessary clone when extracting identifier from object name
mvzink Jan 9, 2025
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
Prev Previous commit
Next Next commit
Merge branch 'main' into mysql-users
mvzink committed Dec 12, 2024
commit f6b2a6aa7cae7c450692d170b23918bc00467e7a
18 changes: 18 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
@@ -5051,6 +5051,24 @@ impl Display for CascadeOption {
}
}

/// Transaction started with [ TRANSACTION | WORK ]
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum BeginTransactionKind {
Transaction,
Work,
}

impl Display for BeginTransactionKind {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
BeginTransactionKind::Transaction => write!(f, "TRANSACTION"),
BeginTransactionKind::Work => write!(f, "WORK"),
}
}
}

/// Can use to describe options in create sequence or table column type identity
/// [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4 changes: 4 additions & 0 deletions src/dialect/generic.rs
Original file line number Diff line number Diff line change
@@ -124,6 +124,10 @@ impl Dialect for GenericDialect {
true
}

fn supports_struct_literal(&self) -> bool {
true
}

fn supports_user_host_grantee(&self) -> bool {
true
}
20 changes: 20 additions & 0 deletions src/dialect/mod.rs
Original file line number Diff line number Diff line change
@@ -365,6 +365,26 @@ pub trait Dialect: Debug + Any {
self.supports_trailing_commas()
}

/// Returns true if the dialect supports double dot notation for object names
///
/// Example
/// ```sql
/// SELECT * FROM db_name..table_name
/// ```
fn supports_object_name_double_dot_notation(&self) -> bool {
false
}

/// Return true if the dialect supports the STRUCT literal
///
/// Example
/// ```sql
/// SELECT STRUCT(1 as one, 'foo' as foo, false)
/// ```
fn supports_struct_literal(&self) -> bool {
false
}

/// Does the dialect support MySQL-style `'user'@'host'` grantee syntax?
fn supports_user_host_grantee(&self) -> bool {
false
7 changes: 7 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -8589,6 +8589,13 @@ impl<'a> Parser<'a> {
span,
}
} else {
if self.dialect.supports_object_name_double_dot_notation()
&& idents.len() == 1
&& self.consume_token(&Token::Period)
{
// Empty string here means default schema
idents.push(Ident::new(""));
}
self.parse_identifier(in_table_clause)?
};
idents.push(ident);
22 changes: 22 additions & 0 deletions tests/sqlparser_mysql.rs
Original file line number Diff line number Diff line change
@@ -3200,3 +3200,25 @@ fn parse_create_view_multiple_params() {
unreachable!()
}
}

#[test]
fn parse_longblob_type() {
let sql = "CREATE TABLE foo (bar LONGBLOB)";
let stmt = mysql_and_generic().verified_stmt(sql);
if let Statement::CreateTable(CreateTable { columns, .. }) = stmt {
assert_eq!(columns.len(), 1);
assert_eq!(columns[0].data_type, DataType::LongBlob);
} else {
unreachable!()
}
mysql_and_generic().verified_stmt("CREATE TABLE foo (bar TINYBLOB)");
mysql_and_generic().verified_stmt("CREATE TABLE foo (bar MEDIUMBLOB)");
mysql_and_generic().verified_stmt("CREATE TABLE foo (bar TINYTEXT)");
mysql_and_generic().verified_stmt("CREATE TABLE foo (bar MEDIUMTEXT)");
mysql_and_generic().verified_stmt("CREATE TABLE foo (bar LONGTEXT)");
}

#[test]
fn parse_begin_without_transaction() {
mysql().verified_stmt("BEGIN");
}
You are viewing a condensed version of this merge commit. You can view the full changes here.