Support CHARSET and ENGINE clauses on CREATE TABLE for mysql (#392)

* Add support for SET and ENUM types

See https://dev.mysql.com/doc/refman/8.0/en/set.html
and https://dev.mysql.com/doc/refman/8.0/en/enum.html

* Add support for mysql ENGINE and DEFAULT CHARSET in CREATE TABLE

See https://dev.mysql.com/doc/refman/8.0/en/create-table.html

* Add support for COMMENT and CHARACTER SET field attributes

See https://dev.mysql.com/doc/refman/8.0/en/create-table.html
This commit is contained in:
Jakob Truelsen 2022-02-08 16:08:56 +01:00 committed by GitHub
parent 34fedf311d
commit e4959696b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 187 additions and 4 deletions

View file

@ -155,6 +155,93 @@ fn parse_create_table_auto_increment() {
}
}
#[test]
fn parse_create_table_set_enum() {
let sql = "CREATE TABLE foo (bar SET('a', 'b'), baz ENUM('a', 'b'))";
match mysql().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
assert_eq!(name.to_string(), "foo");
assert_eq!(
vec![
ColumnDef {
name: Ident::new("bar"),
data_type: DataType::Set(vec!["a".to_string(), "b".to_string()]),
collation: None,
options: vec![],
},
ColumnDef {
name: Ident::new("baz"),
data_type: DataType::Enum(vec!["a".to_string(), "b".to_string()]),
collation: None,
options: vec![],
}
],
columns
);
}
_ => unreachable!(),
}
}
#[test]
fn parse_create_table_engine_default_charset() {
let sql = "CREATE TABLE foo (id INT(11)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3";
match mysql().verified_stmt(sql) {
Statement::CreateTable {
name,
columns,
engine,
default_charset,
..
} => {
assert_eq!(name.to_string(), "foo");
assert_eq!(
vec![ColumnDef {
name: Ident::new("id"),
data_type: DataType::Int(Some(11)),
collation: None,
options: vec![],
},],
columns
);
assert_eq!(engine, Some("InnoDB".to_string()));
assert_eq!(default_charset, Some("utf8mb3".to_string()));
}
_ => unreachable!(),
}
}
#[test]
fn parse_create_table_comment_character_set() {
let sql = "CREATE TABLE foo (s TEXT CHARACTER SET utf8mb4 COMMENT 'comment')";
match mysql().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
assert_eq!(name.to_string(), "foo");
assert_eq!(
vec![ColumnDef {
name: Ident::new("s"),
data_type: DataType::Text,
collation: None,
options: vec![
ColumnOptionDef {
name: None,
option: ColumnOption::CharacterSet(ObjectName(vec![Ident::new(
"utf8mb4"
)]))
},
ColumnOptionDef {
name: None,
option: ColumnOption::Comment("comment".to_string())
}
],
},],
columns
);
}
_ => unreachable!(),
}
}
#[test]
fn parse_quote_identifiers() {
let sql = "CREATE TABLE `PRIMARY` (`BEGIN` INT PRIMARY KEY)";