From 3662bdab8477c70847583b4ec4d69112b484bc5a Mon Sep 17 00:00:00 2001 From: Luiz Carvalho Date: Fri, 14 Jul 2023 20:27:53 -0300 Subject: [PATCH] fix(sqlite): encode bool as integer (#2620) --- Cargo.toml | 5 +++++ sqlx-sqlite/src/any.rs | 1 + tests/sqlite/any.rs | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 tests/sqlite/any.rs diff --git a/Cargo.toml b/Cargo.toml index cc09b4b1..e48a8857 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/sqlx-sqlite/src/any.rs b/sqlx-sqlite/src/any.rs index 3f2b32c6..3bb22a33 100644 --- a/sqlx-sqlite/src/any.rs +++ b/sqlx-sqlite/src/any.rs @@ -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), diff --git a/tests/sqlite/any.rs b/tests/sqlite/any.rs new file mode 100644 index 00000000..601f171e --- /dev/null +++ b/tests/sqlite/any.rs @@ -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::().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(()) +}