Skip to content

Commit

Permalink
fix(sqlite): encode bool as integer (#2620)
Browse files Browse the repository at this point in the history
  • Loading branch information
saiintbrisson authored Jul 14, 2023
1 parent 1d1095e commit 3662bda
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ name = "sqlite"
path = "tests/sqlite/sqlite.rs"
required-features = ["sqlite"]

[[test]]
name = "sqlite-any"
path = "tests/sqlite/any.rs"
required-features = ["sqlite"]

[[test]]
name = "sqlite-types"
path = "tests/sqlite/types.rs"
Expand Down
1 change: 1 addition & 0 deletions sqlx-sqlite/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ fn map_arguments(args: AnyArguments<'_>) -> SqliteArguments<'_> {
.into_iter()
.map(|val| match val {
AnyValueKind::Null => SqliteArgumentValue::Null,
AnyValueKind::Bool(b) => SqliteArgumentValue::Int(b as i32),
AnyValueKind::SmallInt(i) => SqliteArgumentValue::Int(i as i32),
AnyValueKind::Integer(i) => SqliteArgumentValue::Int(i),
AnyValueKind::BigInt(i) => SqliteArgumentValue::Int64(i),
Expand Down
19 changes: 19 additions & 0 deletions tests/sqlite/any.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use sqlx::{Any, Sqlite};
use sqlx_test::new;

#[sqlx_macros::test]
async fn it_encodes_bool_with_any() -> anyhow::Result<()> {
sqlx::any::install_default_drivers();
let mut conn = new::<Any>().await?;

let res = sqlx::query("INSERT INTO accounts VALUES (?, ?, ?)")
.bind(87)
.bind("Harrison Ford")
.bind(true)
.execute(&mut conn)
.await
.expect("failed to encode bool");
assert_eq!(res.rows_affected(), 1);

Ok(())
}

0 comments on commit 3662bda

Please sign in to comment.