Skip to content
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
12 changes: 8 additions & 4 deletions sqlx-sqlite/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,14 @@ impl ValueHandle {
unsafe { Self::try_dup_of(self.value.as_ptr(), self.column_type.clone()) }
}

fn type_info(&self) -> SqliteTypeInfo {
let value_type = SqliteTypeInfo(DataType::from_code(unsafe {
fn value_type_info(&self) -> SqliteTypeInfo {
SqliteTypeInfo(DataType::from_code(unsafe {
sqlite3_value_type(self.value.as_ptr())
}));
}))
}

fn type_info(&self) -> SqliteTypeInfo {
let value_type = self.value_type_info();

// Assume the actual value type is more accurate, if it's not NULL.
match &self.column_type {
Expand All @@ -305,7 +309,7 @@ impl ValueHandle {
}

fn is_null(&self) -> bool {
self.type_info().is_null()
self.value_type_info().is_null()
}
}

Expand Down
22 changes: 22 additions & 0 deletions tests/sqlite/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,3 +1416,25 @@ enum SqliteTransactionState {
Read,
Write,
}

#[sqlx_macros::test]
async fn issue_3982() -> anyhow::Result<()> {
let mut conn = new::<Sqlite>().await?;

let r = sqlx::raw_sql("insert into products(product_no) values(1)")
.execute(&mut conn)
.await?;
assert_eq!(r.rows_affected(), 1);

let (name,) = sqlx::query_as::<_, (Option<String>,)>(
r#"
select name from products where name IS NULL
"#,
)
.fetch_one(&mut conn)
.await?;

assert_eq!(name, None,);

Ok(())
}
4 changes: 4 additions & 0 deletions tests/sqlite/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ test_type!(str<String>(Sqlite,
"''" == ""
));

test_type!(null_str<Option<String>>(Sqlite,
"NULL" == None::<String>
));

test_type!(bytes<Vec<u8>>(Sqlite,
"X'DEADBEEF'"
== vec![0xDE_u8, 0xAD, 0xBE, 0xEF],
Expand Down
Loading