Support identifiers quoted with backticks in the MySQL dialect (#247)

Per https://dev.mysql.com/doc/refman/8.0/en/identifiers.html
MySQL historically supports `identifiers quoted in backticks`
in addition to the ANSI "quoting style" (assuming ANSI_QUOTES mode).
This commit is contained in:
mz 2020-07-30 09:22:29 +08:00 committed by GitHub
parent 1337820c06
commit 9e7e30282e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View file

@ -106,7 +106,7 @@ fn parse_create_table_auto_increment() {
assert_eq!(name.to_string(), "foo");
assert_eq!(
vec![ColumnDef {
name: "bar".into(),
name: Ident::new("bar"),
data_type: DataType::Int,
collation: None,
options: vec![
@ -129,6 +129,29 @@ fn parse_create_table_auto_increment() {
}
}
#[test]
fn parse_quote_identifiers() {
let sql = "CREATE TABLE `PRIMARY` (`BEGIN` INT PRIMARY KEY)";
match mysql().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
assert_eq!(name.to_string(), "`PRIMARY`");
assert_eq!(
vec![ColumnDef {
name: Ident::with_quote('`', "BEGIN"),
data_type: DataType::Int,
collation: None,
options: vec![ColumnOptionDef {
name: None,
option: ColumnOption::Unique { is_primary: true }
}],
}],
columns
);
}
_ => unreachable!(),
}
}
fn mysql() -> TestedDialects {
TestedDialects {
dialects: vec![Box::new(MySqlDialect {})],