fix(sqlite): encode bool as integer (#2620)

This commit is contained in:
Luiz Carvalho 2023-07-14 20:27:53 -03:00 committed by GitHub
parent 1d1095e94f
commit 3662bdab84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

View file

@ -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"

View file

@ -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),

19
tests/sqlite/any.rs Normal file
View file

@ -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(())
}