mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 06:24:16 +00:00
Fix (again) the handling of nulls in mysql and add an integration test for it
This commit is contained in:
parent
7118247692
commit
60d45ac44b
2 changed files with 20 additions and 6 deletions
|
@ -92,13 +92,13 @@ impl Row {
|
|||
let mut index = 0;
|
||||
|
||||
for column_idx in 0..columns.len() {
|
||||
let null = if column_idx % 8 > 5 {
|
||||
null_bitmap[column_idx + 1 / 8] & (4 << (column_idx % 8) as u8)
|
||||
} else {
|
||||
null_bitmap[column_idx / 8] & (1 << (column_idx % 8) as u8)
|
||||
};
|
||||
// the null index for a column starts at the 3rd bit in the null bitmap
|
||||
// for no reason at all besides mysql probably
|
||||
let column_null_idx = column_idx + 2;
|
||||
let is_null =
|
||||
null_bitmap[column_null_idx / 8] & (1 << (column_null_idx % 8) as u8) != 0;
|
||||
|
||||
if null != 0 {
|
||||
if is_null {
|
||||
values.push(None);
|
||||
} else {
|
||||
let size = match columns[column_idx] {
|
||||
|
|
|
@ -50,6 +50,20 @@ CREATE TEMPORARY TABLE users (id INTEGER PRIMARY KEY)
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
async fn it_selects_null() -> anyhow::Result<()> {
|
||||
let mut conn = connect().await?;
|
||||
|
||||
let row = sqlx::query("SELECT NULL").fetch_one(&mut conn).await?;
|
||||
|
||||
let val: Option<i32> = row.get(0);
|
||||
|
||||
assert!(val.is_none());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
async fn pool_immediately_fails_with_db_error() -> anyhow::Result<()> {
|
||||
|
|
Loading…
Reference in a new issue