Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support $NNN bind parameters for sqlite #789

Merged
merged 1 commit into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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