mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-06 05:42:38 +00:00
support sqlite bind parameters of the form $NNN
This commit is contained in:
parent
7726e16292
commit
12b4250454
@ -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));
|
||||
}
|
||||
|
||||
@ -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?;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user