mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 06:18:17 +00:00
Fix parse error on some prepared statement placeholders (#604)
sqlparser can now parse all the prepared statement placeholders supported by SQLite: - ? - ?NNN - @VVV - :VVV - $VVV See: https://www.sqlite.org/lang_expr.html#varparam This does not break existing support for postgresql's '@' operator Fixes #603
This commit is contained in:
parent
3ac1bb5b80
commit
604f755a59
4 changed files with 45 additions and 12 deletions
|
@ -16,8 +16,10 @@
|
|||
|
||||
#[macro_use]
|
||||
mod test_utils;
|
||||
|
||||
use test_utils::*;
|
||||
|
||||
use sqlparser::ast::SelectItem::UnnamedExpr;
|
||||
use sqlparser::ast::*;
|
||||
use sqlparser::dialect::{GenericDialect, SQLiteDialect};
|
||||
use sqlparser::tokenizer::Token;
|
||||
|
@ -73,14 +75,14 @@ fn parse_create_table_auto_increment() {
|
|||
options: vec![
|
||||
ColumnOptionDef {
|
||||
name: None,
|
||||
option: ColumnOption::Unique { is_primary: true }
|
||||
option: ColumnOption::Unique { is_primary: true },
|
||||
},
|
||||
ColumnOptionDef {
|
||||
name: None,
|
||||
option: ColumnOption::DialectSpecific(vec![Token::make_keyword(
|
||||
"AUTOINCREMENT"
|
||||
)])
|
||||
}
|
||||
)]),
|
||||
},
|
||||
],
|
||||
}],
|
||||
columns
|
||||
|
@ -118,6 +120,19 @@ fn parse_create_sqlite_quote() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_placeholder() {
|
||||
// In postgres, this would be the absolute value operator '@' applied to the column 'xxx'
|
||||
// But in sqlite, this is a named parameter.
|
||||
// see https://www.sqlite.org/lang_expr.html#varparam
|
||||
let sql = "SELECT @xxx";
|
||||
let ast = sqlite().verified_only_select(sql);
|
||||
assert_eq!(
|
||||
ast.projection[0],
|
||||
UnnamedExpr(Expr::Value(Value::Placeholder("@xxx".into()))),
|
||||
);
|
||||
}
|
||||
|
||||
fn sqlite() -> TestedDialects {
|
||||
TestedDialects {
|
||||
dialects: vec![Box::new(SQLiteDialect {})],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue