mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-22 16:29:20 +08:00
Ensure empty array Params impl can trigger Error::InvalidParameterCount when needed
This commit is contained in:
parent
22121772a2
commit
a312582d11
@ -161,7 +161,7 @@ pub const NO_PARAMS: &[&dyn ToSql] = &[];
|
||||
#[macro_export]
|
||||
macro_rules! params {
|
||||
() => {
|
||||
(&[] as &[&dyn $crate::ToSql])
|
||||
&[] as &[&dyn $crate::ToSql]
|
||||
};
|
||||
($($param:expr),+ $(,)?) => {
|
||||
&[$(&$param as &dyn $crate::ToSql),+] as &[&dyn $crate::ToSql]
|
||||
@ -198,12 +198,12 @@ macro_rules! params {
|
||||
#[macro_export]
|
||||
macro_rules! named_params {
|
||||
() => {
|
||||
(&[] as &[(&str, &dyn $crate::ToSql)])
|
||||
&[] as &[(&str, &dyn $crate::ToSql)]
|
||||
};
|
||||
// Note: It's a lot more work to support this as part of the same macro as
|
||||
// `params!`, unfortunately.
|
||||
($($param_name:literal: $param_val:expr),+ $(,)?) => {
|
||||
(&[$(($param_name, &$param_val as &dyn $crate::ToSql)),+] as &[(&str, &dyn $crate::ToSql)])
|
||||
&[$(($param_name, &$param_val as &dyn $crate::ToSql)),+] as &[(&str, &dyn $crate::ToSql)]
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -172,8 +172,11 @@ pub trait Params: Sealed {
|
||||
impl Sealed for [&dyn ToSql; 0] {}
|
||||
impl Params for [&dyn ToSql; 0] {
|
||||
#[inline]
|
||||
fn bind_in(self, _: &mut Statement<'_>) -> Result<()> {
|
||||
Ok(())
|
||||
fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
||||
// Note: Can't just return `Ok(())` — `Statement::bind_parameters`
|
||||
// checks that the right number of params were passed too.
|
||||
// TODO: we should have tests for `Error::InvalidParameterCount`...
|
||||
stmt.bind_parameters(crate::params![])
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user