Skip to content

Commit

Permalink
Merge branch 'pub-raw-statement-v0.26.2' into integration/lentil-v0.26.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandall committed Dec 10, 2021
2 parents 66052e2 + aa25225 commit e7197ae
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ with-asan = ["libsqlite3-sys/with-asan"]
column_decltype = []
wasm32-wasi-vfs = ["libsqlite3-sys/wasm32-wasi-vfs"]
winsqlite3 = ["libsqlite3-sys/winsqlite3"]
# make RawStatement public
public-raw-statement = []

# Helper feature for enabling most non-build-related optional features
# or dependencies (except `session`). This is useful for running tests / clippy
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ use std::sync::{Arc, Mutex};

use crate::cache::StatementCache;
use crate::inner_connection::{InnerConnection, BYPASS_SQLITE_INIT};
#[cfg(feature = "public-raw-statement")]
pub use crate::raw_statement::RawStatement;
#[cfg(not(feature = "public-raw-statement"))]
use crate::raw_statement::RawStatement;
use crate::types::ValueRef;

Expand Down
3 changes: 2 additions & 1 deletion src/raw_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::os::raw::c_int;
use std::ptr;
use std::sync::Arc;

// Private newtype for raw sqlite3_stmts that finalize themselves when dropped.
/// Private newtype for raw sqlite3_stmts that finalize themselves when dropped.
#[derive(Debug)]
pub struct RawStatement {
ptr: *mut ffi::sqlite3_stmt,
Expand All @@ -28,6 +28,7 @@ pub struct RawStatement {
statement_cache_key: Option<Arc<str>>,
}

#[allow(clippy::missing_safety_doc, missing_docs)]
impl RawStatement {
#[inline]
pub unsafe fn new(stmt: *mut ffi::sqlite3_stmt, tail: usize) -> RawStatement {
Expand Down
14 changes: 10 additions & 4 deletions src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,9 @@ impl Statement<'_> {
})
}

/// Bind positional parameters to statement
#[inline]
pub(crate) fn bind_parameters<P>(&mut self, params: P) -> Result<()>
pub fn bind_parameters<P>(&mut self, params: P) -> Result<()>
where
P: IntoIterator,
P::Item: ToSql,
Expand All @@ -566,8 +567,9 @@ impl Statement<'_> {
}
}

/// Bind named parameters to statement
#[inline]
pub(crate) fn bind_parameters_named<T: ?Sized + ToSql>(
pub fn bind_parameters_named<T: ?Sized + ToSql>(
&mut self,
params: &[(&str, &T)],
) -> Result<()> {
Expand Down Expand Up @@ -812,11 +814,15 @@ impl Statement<'_> {
Ok(())
}

/// Safety: This is unsafe, because using `sqlite3_stmt` after the
/// Convert Statement into a RawStatement
///
/// # Safety
///
/// This is unsafe, because using `sqlite3_stmt` after the
/// connection has closed is illegal, but `RawStatement` does not enforce
/// this, as it loses our protective `'conn` lifetime bound.
#[inline]
pub(crate) unsafe fn into_raw(mut self) -> RawStatement {
pub unsafe fn into_raw(mut self) -> RawStatement {
let mut stmt = RawStatement::new(ptr::null_mut(), 0);
mem::swap(&mut stmt, &mut self.stmt);
stmt
Expand Down

0 comments on commit e7197ae

Please sign in to comment.