mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +08:00
Make it clear bind_in is not public, and inline functions passing large arrays by value to avoid too much copying
This commit is contained in:
parent
2e08f8b31d
commit
19b0772f3f
@ -163,7 +163,7 @@ pub trait Params: Sealed {
|
|||||||
//
|
//
|
||||||
// For now, just hide the function in the docs...
|
// For now, just hide the function in the docs...
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()>;
|
fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicitly impl for empty array. Critically, for `conn.execute([])` to be
|
// Explicitly impl for empty array. Critically, for `conn.execute([])` to be
|
||||||
@ -172,7 +172,7 @@ pub trait Params: Sealed {
|
|||||||
impl Sealed for [&dyn ToSql; 0] {}
|
impl Sealed for [&dyn ToSql; 0] {}
|
||||||
impl Params for [&dyn ToSql; 0] {
|
impl Params for [&dyn ToSql; 0] {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
||||||
// Note: Can't just return `Ok(())` — `Statement::bind_parameters`
|
// Note: Can't just return `Ok(())` — `Statement::bind_parameters`
|
||||||
// checks that the right number of params were passed too.
|
// checks that the right number of params were passed too.
|
||||||
// TODO: we should have tests for `Error::InvalidParameterCount`...
|
// TODO: we should have tests for `Error::InvalidParameterCount`...
|
||||||
@ -183,7 +183,7 @@ impl Params for [&dyn ToSql; 0] {
|
|||||||
impl Sealed for &[&dyn ToSql] {}
|
impl Sealed for &[&dyn ToSql] {}
|
||||||
impl Params for &[&dyn ToSql] {
|
impl Params for &[&dyn ToSql] {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
||||||
stmt.bind_parameters(self)
|
stmt.bind_parameters(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ impl Params for &[&dyn ToSql] {
|
|||||||
impl Sealed for &[(&str, &dyn ToSql)] {}
|
impl Sealed for &[(&str, &dyn ToSql)] {}
|
||||||
impl Params for &[(&str, &dyn ToSql)] {
|
impl Params for &[(&str, &dyn ToSql)] {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
||||||
stmt.bind_parameters_named(self)
|
stmt.bind_parameters_named(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,19 +202,20 @@ macro_rules! impl_for_array_ref {
|
|||||||
// avoid the compile time hit from making them all inline for now.
|
// avoid the compile time hit from making them all inline for now.
|
||||||
impl<T: ToSql + ?Sized> Sealed for &[&T; $N] {}
|
impl<T: ToSql + ?Sized> Sealed for &[&T; $N] {}
|
||||||
impl<T: ToSql + ?Sized> Params for &[&T; $N] {
|
impl<T: ToSql + ?Sized> Params for &[&T; $N] {
|
||||||
fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
||||||
stmt.bind_parameters(self)
|
stmt.bind_parameters(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<T: ToSql + ?Sized> Sealed for &[(&str, &T); $N] {}
|
impl<T: ToSql + ?Sized> Sealed for &[(&str, &T); $N] {}
|
||||||
impl<T: ToSql + ?Sized> Params for &[(&str, &T); $N] {
|
impl<T: ToSql + ?Sized> Params for &[(&str, &T); $N] {
|
||||||
fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
||||||
stmt.bind_parameters_named(self)
|
stmt.bind_parameters_named(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<T: ToSql> Sealed for [T; $N] {}
|
impl<T: ToSql> Sealed for [T; $N] {}
|
||||||
impl<T: ToSql> Params for [T; $N] {
|
impl<T: ToSql> Params for [T; $N] {
|
||||||
fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
#[inline]
|
||||||
|
fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
||||||
stmt.bind_parameters(&self)
|
stmt.bind_parameters(&self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -351,7 +352,7 @@ where
|
|||||||
I::Item: ToSql,
|
I::Item: ToSql,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
|
||||||
stmt.bind_parameters(self.0)
|
stmt.bind_parameters(self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ impl Statement<'_> {
|
|||||||
/// underlying SQLite call fails.
|
/// underlying SQLite call fails.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn execute<P: Params>(&mut self, params: P) -> Result<usize> {
|
pub fn execute<P: Params>(&mut self, params: P) -> Result<usize> {
|
||||||
params.bind_in(self)?;
|
params.__bind_in(self)?;
|
||||||
self.execute_with_bound_parameters()
|
self.execute_with_bound_parameters()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ impl Statement<'_> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn query<P: Params>(&mut self, params: P) -> Result<Rows<'_>> {
|
pub fn query<P: Params>(&mut self, params: P) -> Result<Rows<'_>> {
|
||||||
self.check_readonly()?;
|
self.check_readonly()?;
|
||||||
params.bind_in(self)?;
|
params.__bind_in(self)?;
|
||||||
Ok(Rows::new(self))
|
Ok(Rows::new(self))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user