mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 15:04:04 +00:00
Support dialect-specific auto-increment column options for MySQL and SQLite (#234)
In MySQL it's AUTO_INCREMENT (see https://dev.mysql.com/doc/refman/8.0/en/create-table.html) and in SQLite it's AUTOINCREMENT. We use `ColumnOption::DialectSpecific(Vec<Token>)` to avoid adding a new variant for each vendor-specific column option.
This commit is contained in:
parent
8020b2e5f0
commit
09ca14fe8e
7 changed files with 95 additions and 5 deletions
|
@ -17,6 +17,7 @@
|
|||
use sqlparser::ast::*;
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
use sqlparser::test_utils::*;
|
||||
use sqlparser::tokenizer::Token;
|
||||
|
||||
#[test]
|
||||
fn parse_create_table_without_rowid() {
|
||||
|
@ -55,6 +56,37 @@ fn parse_create_virtual_table() {
|
|||
sqlite_and_generic().verified_stmt(sql);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_table_auto_increment() {
|
||||
let sql = "CREATE TABLE foo (bar INT PRIMARY KEY AUTOINCREMENT)";
|
||||
match sqlite_and_generic().verified_stmt(sql) {
|
||||
Statement::CreateTable { name, columns, .. } => {
|
||||
assert_eq!(name.to_string(), "foo");
|
||||
assert_eq!(
|
||||
vec![ColumnDef {
|
||||
name: "bar".into(),
|
||||
data_type: DataType::Int,
|
||||
collation: None,
|
||||
options: vec![
|
||||
ColumnOptionDef {
|
||||
name: None,
|
||||
option: ColumnOption::Unique { is_primary: true }
|
||||
},
|
||||
ColumnOptionDef {
|
||||
name: None,
|
||||
option: ColumnOption::DialectSpecific(vec![Token::make_keyword(
|
||||
"AUTOINCREMENT"
|
||||
)])
|
||||
}
|
||||
],
|
||||
}],
|
||||
columns
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn sqlite_and_generic() -> TestedDialects {
|
||||
TestedDialects {
|
||||
// we don't have a separate SQLite dialect, so test only the generic dialect for now
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue