Skip to content

Commit ceac70f

Browse files
authored
fix: Option decoding in any driver (#3172)
1 parent 17d832b commit ceac70f

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

sqlx-core/src/any/type_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub enum AnyTypeInfoKind {
3131

3232
impl TypeInfo for AnyTypeInfo {
3333
fn is_null(&self) -> bool {
34-
false
34+
self.kind == Null
3535
}
3636

3737
fn name(&self) -> &str {

sqlx-core/src/any/value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl Value for AnyValue {
9292
}
9393

9494
fn is_null(&self) -> bool {
95-
false
95+
matches!(self.kind, AnyValueKind::Null)
9696
}
9797
}
9898

@@ -120,6 +120,6 @@ impl<'a> ValueRef<'a> for AnyValueRef<'a> {
120120
}
121121

122122
fn is_null(&self) -> bool {
123-
false
123+
matches!(self.kind, AnyValueKind::Null)
124124
}
125125
}

sqlx-core/src/types/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! An `Option<T>` represents a potentially `NULL` value from SQL.
1919
//!
2020
21-
use crate::database::Database;
21+
use crate::{database::Database, type_info::TypeInfo};
2222

2323
#[cfg(feature = "bstr")]
2424
#[cfg_attr(docsrs, doc(cfg(feature = "bstr")))]
@@ -234,6 +234,6 @@ impl<T: Type<DB>, DB: Database> Type<DB> for Option<T> {
234234
}
235235

236236
fn compatible(ty: &DB::TypeInfo) -> bool {
237-
<T as Type<DB>>::compatible(ty)
237+
ty.is_null() || <T as Type<DB>>::compatible(ty)
238238
}
239239
}

0 commit comments

Comments
 (0)