Skip to content

Commit 3662bda

Browse files
fix(sqlite): encode bool as integer (#2620)
1 parent 1d1095e commit 3662bda

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ name = "sqlite"
211211
path = "tests/sqlite/sqlite.rs"
212212
required-features = ["sqlite"]
213213

214+
[[test]]
215+
name = "sqlite-any"
216+
path = "tests/sqlite/any.rs"
217+
required-features = ["sqlite"]
218+
214219
[[test]]
215220
name = "sqlite-types"
216221
path = "tests/sqlite/types.rs"

sqlx-sqlite/src/any.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ fn map_arguments(args: AnyArguments<'_>) -> SqliteArguments<'_> {
205205
.into_iter()
206206
.map(|val| match val {
207207
AnyValueKind::Null => SqliteArgumentValue::Null,
208+
AnyValueKind::Bool(b) => SqliteArgumentValue::Int(b as i32),
208209
AnyValueKind::SmallInt(i) => SqliteArgumentValue::Int(i as i32),
209210
AnyValueKind::Integer(i) => SqliteArgumentValue::Int(i),
210211
AnyValueKind::BigInt(i) => SqliteArgumentValue::Int64(i),

tests/sqlite/any.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use sqlx::{Any, Sqlite};
2+
use sqlx_test::new;
3+
4+
#[sqlx_macros::test]
5+
async fn it_encodes_bool_with_any() -> anyhow::Result<()> {
6+
sqlx::any::install_default_drivers();
7+
let mut conn = new::<Any>().await?;
8+
9+
let res = sqlx::query("INSERT INTO accounts VALUES (?, ?, ?)")
10+
.bind(87)
11+
.bind("Harrison Ford")
12+
.bind(true)
13+
.execute(&mut conn)
14+
.await
15+
.expect("failed to encode bool");
16+
assert_eq!(res.rows_affected(), 1);
17+
18+
Ok(())
19+
}

0 commit comments

Comments
 (0)