mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +08:00
Add support for querying sqlite_stmt_status
This commit is contained in:
parent
6d1c915c2b
commit
ec879337af
@ -90,7 +90,7 @@ use crate::error::{error_from_handle, error_from_sqlite_code};
|
|||||||
use crate::raw_statement::RawStatement;
|
use crate::raw_statement::RawStatement;
|
||||||
use crate::types::{ToSql, ValueRef};
|
use crate::types::{ToSql, ValueRef};
|
||||||
|
|
||||||
pub use crate::statement::Statement;
|
pub use crate::statement::{Statement, StatementStatus};
|
||||||
|
|
||||||
pub use crate::row::{AndThenRows, MappedRows, Row, RowIndex, Rows};
|
pub use crate::row::{AndThenRows, MappedRows, Row, RowIndex, Rows};
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use super::ffi;
|
use super::ffi;
|
||||||
use super::unlock_notify;
|
use super::unlock_notify;
|
||||||
|
use super::StatementStatus;
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::os::raw::c_int;
|
use std::os::raw::c_int;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
@ -100,6 +101,11 @@ impl RawStatement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_status(&self, status: StatementStatus, reset: bool) -> i32 {
|
||||||
|
assert!(!self.0.is_null());
|
||||||
|
unsafe { ffi::sqlite3_stmt_status(self.0, status as i32, reset as i32) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for RawStatement {
|
impl Drop for RawStatement {
|
||||||
|
@ -569,6 +569,17 @@ impl<'conn> Statement<'conn> {
|
|||||||
.map(|s| str::from_utf8_unchecked(s.to_bytes()))
|
.map(|s| str::from_utf8_unchecked(s.to_bytes()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the value for one of the status counters for this statement.
|
||||||
|
pub fn get_status(&self, status: StatementStatus) -> i32 {
|
||||||
|
self.stmt.get_status(status, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reset the value of one of the status counters for this statement,
|
||||||
|
/// returning the value it had before resetting.
|
||||||
|
pub fn reset_status(&self, status: StatementStatus) -> i32 {
|
||||||
|
self.stmt.get_status(status, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'conn> Into<RawStatement> for Statement<'conn> {
|
impl<'conn> Into<RawStatement> for Statement<'conn> {
|
||||||
@ -670,6 +681,32 @@ impl<'conn> Statement<'conn> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Prepared statement status counters.
|
||||||
|
///
|
||||||
|
/// See https://www.sqlite.org/c3ref/c_stmtstatus_counter.html
|
||||||
|
/// for explanations of each.
|
||||||
|
///
|
||||||
|
/// Note that depending on your version of SQLite, all of these
|
||||||
|
/// may not be available.
|
||||||
|
#[repr(i32)]
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum StatementStatus {
|
||||||
|
/// Equivalent to SQLITE_STMTSTATUS_FULLSCAN_STEP
|
||||||
|
FullscanStep = 1,
|
||||||
|
/// Equivalent to SQLITE_STMTSTATUS_SORT
|
||||||
|
Sort = 2,
|
||||||
|
/// Equivalent to SQLITE_STMTSTATUS_AUTOINDEX
|
||||||
|
AutoIndex = 3,
|
||||||
|
/// Equivalent to SQLITE_STMTSTATUS_VM_STEP
|
||||||
|
VmStep = 4,
|
||||||
|
/// Equivalent to SQLITE_STMTSTATUS_REPREPARE
|
||||||
|
RePrepare = 5,
|
||||||
|
/// Equivalent to SQLITE_STMTSTATUS_RUN
|
||||||
|
Run = 6,
|
||||||
|
/// Equivalent to SQLITE_STMTSTATUS_MEMUSED
|
||||||
|
MemUsed = 99,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::{Connection, Error, Result, NO_PARAMS};
|
use crate::{Connection, Error, Result, NO_PARAMS};
|
||||||
|
Loading…
Reference in New Issue
Block a user