mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-31 03:07:20 +00:00
feat: add arg placeholder (#420)
Co-authored-by: gamife <gamife9886@gmail.com>
This commit is contained in:
parent
1da49c15c7
commit
899f91b1f6
4 changed files with 60 additions and 1 deletions
|
@ -22,7 +22,9 @@
|
|||
mod test_utils;
|
||||
use matches::assert_matches;
|
||||
use sqlparser::ast::*;
|
||||
use sqlparser::dialect::{GenericDialect, PostgreSqlDialect, SQLiteDialect};
|
||||
use sqlparser::dialect::{
|
||||
AnsiDialect, GenericDialect, MsSqlDialect, PostgreSqlDialect, SQLiteDialect, SnowflakeDialect,
|
||||
};
|
||||
use sqlparser::keywords::ALL_KEYWORDS;
|
||||
use sqlparser::parser::{Parser, ParserError};
|
||||
use test_utils::{
|
||||
|
@ -4160,6 +4162,42 @@ fn test_revoke() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_placeholder() {
|
||||
let sql = "SELECT * FROM student WHERE id = ?";
|
||||
let ast = verified_only_select(sql);
|
||||
assert_eq!(
|
||||
ast.selection,
|
||||
Some(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier(Ident::new("id"))),
|
||||
op: BinaryOperator::Eq,
|
||||
right: Box::new(Expr::Value(Value::Placeholder("?".into())))
|
||||
})
|
||||
);
|
||||
|
||||
let dialects = TestedDialects {
|
||||
dialects: vec![
|
||||
Box::new(GenericDialect {}),
|
||||
Box::new(PostgreSqlDialect {}),
|
||||
Box::new(MsSqlDialect {}),
|
||||
Box::new(AnsiDialect {}),
|
||||
Box::new(SnowflakeDialect {}),
|
||||
// Note: `$` is the starting word for the HiveDialect identifier
|
||||
// Box::new(sqlparser::dialect::HiveDialect {}),
|
||||
],
|
||||
};
|
||||
let sql = "SELECT * FROM student WHERE id = $Id1";
|
||||
let ast = dialects.verified_only_select(sql);
|
||||
assert_eq!(
|
||||
ast.selection,
|
||||
Some(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier(Ident::new("id"))),
|
||||
op: BinaryOperator::Eq,
|
||||
right: Box::new(Expr::Value(Value::Placeholder("$Id1".into())))
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_keywords_sorted() {
|
||||
// assert!(ALL_KEYWORDS.is_sorted())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue