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:
Ophir LOJKINE 2022-09-27 15:58:26 +02:00 committed by GitHub
parent 3ac1bb5b80
commit 604f755a59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 12 deletions

View file

@ -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 {})],