support sqlite bind parameters of the form $NNN

This commit is contained in:
David Yamnitsky 2020-11-03 15:13:54 -05:00 committed by Austin Bonander
parent 7726e16292
commit 12b4250454
2 changed files with 24 additions and 0 deletions

View File

@ -61,6 +61,14 @@ impl SqliteArguments<'_> {
if name.starts_with('?') {
// parameter should have the form ?NNN
atoi(name[1..].as_bytes()).expect("parameter of the form ?NNN")
} else if name.starts_with('$') {
// parameter should have the form $NNN
atoi(name[1..].as_bytes()).ok_or_else(|| {
err_protocol!(
"parameters with non-integer names are not currently supported: {}",
name
)
})?
} else {
return Err(err_protocol!("unsupported SQL parameter format: {}", name));
}

View File

@ -269,6 +269,22 @@ fn it_binds_parameters() -> anyhow::Result<()> {
Ok(())
}
#[sqlx_macros::test]
fn it_binds_dollar_parameters() -> anyhow::Result<()> {
let mut conn = new::<Sqlite>().await?;
let v: (i32, i32) = sqlx::query_as("SELECT $1, $2")
.bind(10_i32)
.bind(11_i32)
.fetch_one(&mut conn)
.await?;
assert_eq!(v.0, 10);
assert_eq!(v.1, 11);
Ok(())
}
#[sqlx_macros::test]
async fn it_executes_queries() -> anyhow::Result<()> {
let mut conn = new::<Sqlite>().await?;