Add SQLite dialect (#248)

This commit is contained in:
mz 2020-07-31 20:09:54 +08:00 committed by GitHub
parent 4452f9bad1
commit f8feff4ef2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 2 deletions

View file

@ -15,7 +15,7 @@
//! generic dialect is also tested (on the inputs it can handle).
use sqlparser::ast::*;
use sqlparser::dialect::GenericDialect;
use sqlparser::dialect::{GenericDialect, SQLiteDialect};
use sqlparser::test_utils::*;
use sqlparser::tokenizer::Token;
@ -87,9 +87,43 @@ fn parse_create_table_auto_increment() {
}
}
#[test]
fn parse_create_sqlite_quote() {
let sql = "CREATE TABLE `PRIMARY` (\"KEY\" INT, [INDEX] INT)";
match sqlite().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
assert_eq!(name.to_string(), "`PRIMARY`");
assert_eq!(
vec![
ColumnDef {
name: Ident::with_quote('"', "KEY"),
data_type: DataType::Int,
collation: None,
options: vec![],
},
ColumnDef {
name: Ident::with_quote('[', "INDEX"),
data_type: DataType::Int,
collation: None,
options: vec![],
},
],
columns
);
}
_ => unreachable!(),
}
}
fn sqlite() -> TestedDialects {
TestedDialects {
dialects: vec![Box::new(SQLiteDialect {})],
}
}
fn sqlite_and_generic() -> TestedDialects {
TestedDialects {
// we don't have a separate SQLite dialect, so test only the generic dialect for now
dialects: vec![Box::new(GenericDialect {})],
dialects: vec![Box::new(SQLiteDialect {}), Box::new(GenericDialect {})],
}
}