Skip to content

Commit

Permalink
support sqlite bind parameters of the form $NNN
Browse files Browse the repository at this point in the history
  • Loading branch information
nitsky authored and abonander committed Nov 6, 2020
1 parent 7726e16 commit 12b4250
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sqlx-core/src/sqlite/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
16 changes: 16 additions & 0 deletions tests/sqlite/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down

0 comments on commit 12b4250

Please sign in to comment.