#![forbid(missing_docs)]
#![allow(clippy::not_unsafe_ptr_arg_deref)]
use std::{
ffi::{CStr, CString},
os, ptr,
};
use crate::connection::Database;
use crate::{bindings::sqlite3_stmt, ehandle::MinSqliteWrapperError};
use crate::{bindings::*, statement::SqlStatement};
pub trait ColumnCapabilities<'a> {
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized;
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized;
}
pub type SqliteNull = ();
pub const SQLITE_NULL: SqliteNull = ();
impl<'a> ColumnCapabilities<'a> for Option<i8> {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe {
if sqlite3_column_type(stmt, i as os::raw::c_int) as u32 == COLUMN_NULL {
return Ok(None);
}
Ok(Some(sqlite3_column_int64(stmt, i as os::raw::c_int) as i8))
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
if let Some(t) = self {
unsafe {
return SqlitePrimaryResult::from_i8(sqlite3_bind_int64(
stmt,
i as os::raw::c_int,
t as os::raw::c_longlong,
) as i8);
}
}
SqlitePrimaryResult::MisMatch
}
}
impl<'a> ColumnCapabilities<'a> for i8 {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe { Ok(sqlite3_column_int64(stmt, i as os::raw::c_int) as Self) }
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe {
SqlitePrimaryResult::from_i8(sqlite3_bind_int64(
stmt,
i as os::raw::c_int,
self as os::raw::c_longlong,
) as i8)
}
}
}
impl<'a> ColumnCapabilities<'a> for Option<u8> {
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe {
if sqlite3_column_type(stmt, i as os::raw::c_int) as u32 == COLUMN_NULL {
return Ok(None);
}
Ok(Some(sqlite3_column_int64(stmt, i as os::raw::c_int) as u8))
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
if let Some(t) = self {
unsafe {
return SqlitePrimaryResult::from_i8(sqlite3_bind_int64(
stmt,
i as os::raw::c_int,
t as os::raw::c_longlong,
) as i8);
}
}
SqlitePrimaryResult::MisMatch
}
}
impl<'a> ColumnCapabilities<'a> for u8 {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe { Ok(sqlite3_column_int64(stmt, i as os::raw::c_int) as Self) }
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe {
SqlitePrimaryResult::from_i8(sqlite3_bind_int64(
stmt,
i as os::raw::c_int,
self as os::raw::c_longlong,
) as i8)
}
}
}
impl<'a> ColumnCapabilities<'a> for Option<i16> {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe {
if sqlite3_column_type(stmt, i as os::raw::c_int) as u32 == COLUMN_NULL {
return Ok(None);
}
Ok(Some(sqlite3_column_int64(stmt, i as os::raw::c_int) as i16))
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
if let Some(t) = self {
unsafe {
return SqlitePrimaryResult::from_i8(sqlite3_bind_int64(
stmt,
i as os::raw::c_int,
t as os::raw::c_longlong,
) as i8);
}
}
SqlitePrimaryResult::MisMatch
}
}
impl<'a> ColumnCapabilities<'a> for i16 {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe { Ok(sqlite3_column_int64(stmt, i as os::raw::c_int) as Self) }
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe {
SqlitePrimaryResult::from_i8(sqlite3_bind_int64(
stmt,
i as os::raw::c_int,
self as os::raw::c_longlong,
) as i8)
}
}
}
impl<'a> ColumnCapabilities<'a> for Option<u16> {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe {
if sqlite3_column_type(stmt, i as os::raw::c_int) as u32 == COLUMN_NULL {
return Ok(None);
}
Ok(Some(sqlite3_column_int64(stmt, i as os::raw::c_int) as u16))
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
if let Some(t) = self {
unsafe {
return SqlitePrimaryResult::from_i8(sqlite3_bind_int64(
stmt,
i as os::raw::c_int,
t as os::raw::c_longlong,
) as i8);
}
}
SqlitePrimaryResult::MisMatch
}
}
impl<'a> ColumnCapabilities<'a> for u16 {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe { Ok(sqlite3_column_int64(stmt, i as os::raw::c_int) as Self) }
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe {
SqlitePrimaryResult::from_i8(sqlite3_bind_int64(
stmt,
i as os::raw::c_int,
self as os::raw::c_longlong,
) as i8)
}
}
}
impl<'a> ColumnCapabilities<'a> for Option<i32> {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe {
if sqlite3_column_type(stmt, i as os::raw::c_int) as u32 == COLUMN_NULL {
return Ok(None);
}
Ok(Some(sqlite3_column_int64(stmt, i as os::raw::c_int) as i32))
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
if let Some(t) = self {
unsafe {
return SqlitePrimaryResult::from_i8(sqlite3_bind_int64(
stmt,
i as os::raw::c_int,
t as os::raw::c_longlong,
) as i8);
}
}
SqlitePrimaryResult::MisMatch
}
}
impl<'a> ColumnCapabilities<'a> for i32 {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe { Ok(sqlite3_column_int64(stmt, i as os::raw::c_int) as Self) }
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe {
SqlitePrimaryResult::from_i8(sqlite3_bind_int64(
stmt,
i as os::raw::c_int,
self as os::raw::c_longlong,
) as i8)
}
}
}
impl<'a> ColumnCapabilities<'a> for Option<u32> {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe {
if sqlite3_column_type(stmt, i as os::raw::c_int) as u32 == COLUMN_NULL {
return Ok(None);
}
Ok(Some(sqlite3_column_int64(stmt, i as os::raw::c_int) as u32))
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
if let Some(t) = self {
unsafe {
return SqlitePrimaryResult::from_i8(sqlite3_bind_int64(
stmt,
i as os::raw::c_int,
t as os::raw::c_longlong,
) as i8);
}
}
SqlitePrimaryResult::MisMatch
}
}
impl<'a> ColumnCapabilities<'a> for u32 {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe { Ok(sqlite3_column_int64(stmt, i as os::raw::c_int) as Self) }
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe {
SqlitePrimaryResult::from_i8(sqlite3_bind_int64(
stmt,
i as os::raw::c_int,
self as os::raw::c_longlong,
) as i8)
}
}
}
impl<'a> ColumnCapabilities<'a> for Option<i64> {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe {
if sqlite3_column_type(stmt, i as os::raw::c_int) as u32 == COLUMN_NULL {
return Ok(None);
}
Ok(Some(sqlite3_column_int64(stmt, i as os::raw::c_int) as i64))
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
if let Some(t) = self {
unsafe {
return SqlitePrimaryResult::from_i8(sqlite3_bind_int64(
stmt,
i as os::raw::c_int,
t as os::raw::c_longlong,
) as i8);
}
}
SqlitePrimaryResult::MisMatch
}
}
impl<'a> ColumnCapabilities<'a> for i64 {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe { Ok(sqlite3_column_int64(stmt, i as os::raw::c_int) as Self) }
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe {
SqlitePrimaryResult::from_i8(sqlite3_bind_int64(
stmt,
i as os::raw::c_int,
self as os::raw::c_longlong,
) as i8)
}
}
}
impl<'a> ColumnCapabilities<'a> for Option<f32> {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe {
if sqlite3_column_type(stmt, i as os::raw::c_int) as u32 == COLUMN_NULL {
return Ok(None);
}
Ok(Some(sqlite3_column_double(stmt, i as os::raw::c_int) as f32))
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
if let Some(t) = self {
unsafe {
return SqlitePrimaryResult::from_i8(sqlite3_bind_double(
stmt,
i as os::raw::c_int,
t.into(),
) as i8);
}
}
SqlitePrimaryResult::MisMatch
}
}
impl<'a> ColumnCapabilities<'a> for f32 {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe { Ok(sqlite3_column_double(stmt, i as os::raw::c_int) as Self) }
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe {
SqlitePrimaryResult::from_i8(
sqlite3_bind_double(stmt, i as os::raw::c_int, self.into()) as i8,
)
}
}
}
impl<'a> ColumnCapabilities<'a> for Option<f64> {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe {
if sqlite3_column_type(stmt, i as os::raw::c_int) as u32 == COLUMN_NULL {
return Ok(None);
}
Ok(Some(sqlite3_column_double(stmt, i as os::raw::c_int) as f64))
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
if let Some(t) = self {
unsafe {
return SqlitePrimaryResult::from_i8(sqlite3_bind_double(
stmt,
i as os::raw::c_int,
t,
) as i8);
}
}
SqlitePrimaryResult::MisMatch
}
}
impl<'a> ColumnCapabilities<'a> for f64 {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe { Ok(sqlite3_column_double(stmt, i as os::raw::c_int) as Self) }
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe {
SqlitePrimaryResult::from_i8(sqlite3_bind_double(stmt, i as os::raw::c_int, self) as i8)
}
}
}
impl<'a> ColumnCapabilities<'a> for Option<&str> {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe {
if sqlite3_column_type(stmt, i as os::raw::c_int) as u32 == COLUMN_NULL {
return Ok(None);
}
let result = sqlite3_column_text(stmt, i as os::raw::c_int);
Ok(Some(CStr::from_ptr(result as *const _).to_str()?))
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
if let Some(t) = self {
unsafe {
return SqlitePrimaryResult::from_i8(sqlite3_bind_text(
stmt,
i as os::raw::c_int,
t.as_ptr() as *const _,
t.len() as os::raw::c_int,
sqlite_transient(),
) as i8);
}
}
SqlitePrimaryResult::MisMatch
}
}
impl<'a> ColumnCapabilities<'a> for &str {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe {
let result = sqlite3_column_text(stmt, i as os::raw::c_int);
Ok(CStr::from_ptr(result as *const _).to_str()?)
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe {
SqlitePrimaryResult::from_i8(sqlite3_bind_text(
stmt,
i as os::raw::c_int,
self.as_ptr() as *const _,
self.len() as os::raw::c_int,
sqlite_transient(),
) as i8)
}
}
}
impl<'a> ColumnCapabilities<'a> for Option<String> {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe {
if sqlite3_column_type(stmt, i as os::raw::c_int) as u32 == COLUMN_NULL {
return Ok(None);
}
let result = sqlite3_column_text(stmt, i as os::raw::c_int);
Ok(Some(
CStr::from_ptr(result as *const _).to_str()?.to_owned(),
))
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
if let Some(t) = self {
unsafe {
return SqlitePrimaryResult::from_i8(sqlite3_bind_text(
stmt,
i as os::raw::c_int,
t.as_ptr() as *const _,
t.len() as os::raw::c_int,
sqlite_transient(),
) as i8);
}
}
SqlitePrimaryResult::MisMatch
}
}
impl<'a> ColumnCapabilities<'a> for String {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unsafe {
let result = sqlite3_column_text(stmt, i as os::raw::c_int);
Ok(CStr::from_ptr(result as *const _).to_str()?.to_owned())
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe {
SqlitePrimaryResult::from_i8(sqlite3_bind_text(
stmt,
i as os::raw::c_int,
self.as_ptr() as *const _,
self.len() as os::raw::c_int,
sqlite_transient(),
) as i8)
}
}
}
impl<'a> ColumnCapabilities<'a> for Option<Vec<u8>> {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
use ptr::copy_nonoverlapping as copy;
unsafe {
if sqlite3_column_type(stmt, i as os::raw::c_int) as u32 == COLUMN_NULL {
return Ok(None);
}
let pointer = sqlite3_column_blob(stmt, i as os::raw::c_int);
if pointer.is_null() {
return Ok(Some(vec![]));
}
let count = sqlite3_column_bytes(stmt, i as os::raw::c_int) as usize;
let mut buffer = Vec::with_capacity(count);
#[allow(clippy::uninit_vec)]
buffer.set_len(count); copy(pointer as *const u8, buffer.as_mut_ptr(), count);
Ok(Some(buffer))
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe {
if let Some(t) = self {
if t.is_empty() {
return SqlitePrimaryResult::from_i8(sqlite3_bind_zeroblob64(
stmt,
i as os::raw::c_int,
0,
) as i8);
}
return SqlitePrimaryResult::from_i8(sqlite3_bind_blob(
stmt,
i as os::raw::c_int,
t.as_ptr() as *const _,
t.len() as os::raw::c_int,
sqlite_transient(),
) as i8);
}
}
SqlitePrimaryResult::MisMatch
}
}
impl<'a> ColumnCapabilities<'a> for Vec<u8> {
#[inline]
fn get_data(stmt: *mut sqlite3_stmt, i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
use ptr::copy_nonoverlapping as copy;
unsafe {
let pointer = sqlite3_column_blob(stmt, i as os::raw::c_int);
if pointer.is_null() {
return Ok(vec![]);
}
let count = sqlite3_column_bytes(stmt, i as os::raw::c_int) as usize;
let mut buffer = Vec::with_capacity(count);
#[allow(clippy::uninit_vec)]
buffer.set_len(count); copy(pointer as *const u8, buffer.as_mut_ptr(), count);
Ok(buffer)
}
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe {
if self.is_empty() {
return SqlitePrimaryResult::from_i8(sqlite3_bind_zeroblob64(
stmt,
i as os::raw::c_int,
0,
) as i8);
}
SqlitePrimaryResult::from_i8(sqlite3_bind_blob(
stmt,
i as os::raw::c_int,
self.as_ptr() as *const _,
self.len() as os::raw::c_int,
sqlite_transient(),
) as i8)
}
}
}
impl<'a> ColumnCapabilities<'a> for Option<&[u8]> {
fn get_data(_stmt: *mut sqlite3_stmt, _i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unimplemented!()
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
if let Some(t) = self {
unsafe {
if t.is_empty() {
return SqlitePrimaryResult::from_i8(sqlite3_bind_zeroblob64(
stmt,
i as os::raw::c_int,
0,
) as i8);
}
return SqlitePrimaryResult::from_i8(sqlite3_bind_blob(
stmt,
i as os::raw::c_int,
t.as_ptr() as *const _,
t.len() as os::raw::c_int,
sqlite_transient(),
) as i8);
}
}
SqlitePrimaryResult::MisMatch
}
}
impl<'a> ColumnCapabilities<'a> for &[u8] {
fn get_data(_stmt: *mut sqlite3_stmt, _i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unimplemented!()
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe {
if self.is_empty() {
return SqlitePrimaryResult::from_i8(sqlite3_bind_zeroblob64(
stmt,
i as os::raw::c_int,
0,
) as i8);
}
SqlitePrimaryResult::from_i8(sqlite3_bind_blob(
stmt,
i as os::raw::c_int,
self.as_ptr() as *const _,
self.len() as os::raw::c_int,
sqlite_transient(),
) as i8)
}
}
}
impl<'a> ColumnCapabilities<'a> for Option<SqliteNull> {
fn get_data(_stmt: *mut sqlite3_stmt, _i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unimplemented!()
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe { SqlitePrimaryResult::from_i8(sqlite3_bind_null(stmt, i as os::raw::c_int) as i8) }
}
}
impl<'a> ColumnCapabilities<'a> for SqliteNull {
fn get_data(_stmt: *mut sqlite3_stmt, _i: usize) -> Result<Self, MinSqliteWrapperError<'a>>
where
Self: Sized,
{
unimplemented!()
}
fn bind_val(self, stmt: *mut sqlite3_stmt, i: usize) -> SqlitePrimaryResult
where
Self: Sized,
{
unsafe { SqlitePrimaryResult::from_i8(sqlite3_bind_null(stmt, i as os::raw::c_int) as i8) }
}
}
pub trait Operations {
fn execute<'a, F>(
&self,
statement: String,
callback_fn: Option<F>,
) -> Result<SqlitePrimaryResult, MinSqliteWrapperError<'a>>
where
F: FnOnce(SqlitePrimaryResult, String);
fn prepare<'a, F>(
&self,
statement: String,
callback_fn: Option<F>,
) -> Result<SqlStatement, MinSqliteWrapperError<'a>>
where
F: FnOnce(SqlitePrimaryResult, String);
}
impl Operations for Database {
fn execute<'a, F>(
&self,
statement: String,
callback_fn: Option<F>,
) -> Result<SqlitePrimaryResult, MinSqliteWrapperError<'a>>
where
F: FnOnce(SqlitePrimaryResult, String),
{
let st = CString::new(&*statement)?;
unsafe {
let status = sqlite3_exec(self.rp, st.as_ptr(), None, ptr::null_mut(), ptr::null_mut());
if status != SqlitePrimaryResult::Ok as i32 {
if let Some(func) = callback_fn {
func(SqlitePrimaryResult::from_i8(status as i8), statement);
}
}
Ok(SqlitePrimaryResult::from_i8(status as i8))
}
}
fn prepare<'a, F>(
&self,
statement: String,
callback_fn: Option<F>,
) -> Result<SqlStatement, MinSqliteWrapperError<'a>>
where
F: FnOnce(SqlitePrimaryResult, String),
{
let st = CString::new(&*statement)?;
let mut stmt = ptr::null_mut();
let mut tail = ptr::null();
unsafe {
let status = sqlite3_prepare_v2(
self.rp,
st.as_ptr(),
statement.len() as os::raw::c_int,
&mut stmt,
&mut tail,
);
if status != SqlitePrimaryResult::Ok as i32 {
if let Some(func) = callback_fn {
func(SqlitePrimaryResult::from_i8(status as i8), statement);
}
}
}
Ok(SqlStatement::new(stmt))
}
}