Skip to content

Commit

Permalink
Fix Option for Any driver. (#1661)
Browse files Browse the repository at this point in the history
With macro impl_encode_for_option Null values are not added, when creating arguments for the actual driver selected at runtime.
  • Loading branch information
ArGGu authored Feb 16, 2022
1 parent 6674e8b commit 160f345
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion sqlx-core/src/any/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,26 @@ impl_column_index_for_statement!(AnyStatement);
impl_into_maybe_pool!(Any, AnyConnection);

// required because some databases have a different handling of NULL
impl_encode_for_option!(Any);
impl<'q, T> crate::encode::Encode<'q, Any> for Option<T>
where
T: AnyEncode<'q> + 'q,
{
fn encode_by_ref(&self, buf: &mut AnyArgumentBuffer<'q>) -> crate::encode::IsNull {
match &mut buf.0 {
#[cfg(feature = "postgres")]
arguments::AnyArgumentBufferKind::Postgres(args, _) => args.add(self),

#[cfg(feature = "mysql")]
arguments::AnyArgumentBufferKind::MySql(args, _) => args.add(self),

#[cfg(feature = "mssql")]
arguments::AnyArgumentBufferKind::Mssql(args, _) => args.add(self),

#[cfg(feature = "sqlite")]
arguments::AnyArgumentBufferKind::Sqlite(args) => args.add(self),
}

// unused
crate::encode::IsNull::No
}
}

0 comments on commit 160f345

Please sign in to comment.