Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}