mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +08:00
commit
11ee69b571
@ -5,7 +5,6 @@ use std::ops::{Deref, DerefMut};
|
|||||||
use lru_cache::LruCache;
|
use lru_cache::LruCache;
|
||||||
use {Result, Connection, Statement};
|
use {Result, Connection, Statement};
|
||||||
use raw_statement::RawStatement;
|
use raw_statement::RawStatement;
|
||||||
use statement::StatementCrateImpl;
|
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
/// Prepare a SQL statement for execution, returning a previously prepared (but
|
/// Prepare a SQL statement for execution, returning a previously prepared (but
|
||||||
|
@ -80,10 +80,8 @@ use raw_statement::RawStatement;
|
|||||||
use cache::StatementCache;
|
use cache::StatementCache;
|
||||||
|
|
||||||
pub use statement::Statement;
|
pub use statement::Statement;
|
||||||
use statement::StatementCrateImpl;
|
|
||||||
|
|
||||||
pub use row::{Row, Rows, MappedRows, AndThenRows, RowIndex};
|
pub use row::{Row, Rows, MappedRows, AndThenRows, RowIndex};
|
||||||
use row::RowsCrateImpl;
|
|
||||||
|
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
pub use transaction::{SqliteTransaction, SqliteTransactionBehavior};
|
pub use transaction::{SqliteTransaction, SqliteTransactionBehavior};
|
||||||
|
34
src/row.rs
34
src/row.rs
@ -3,7 +3,6 @@ use std::marker::PhantomData;
|
|||||||
|
|
||||||
use super::{Statement, Error, Result};
|
use super::{Statement, Error, Result};
|
||||||
use types::{FromSql, FromSqlError};
|
use types::{FromSql, FromSqlError};
|
||||||
use statement::StatementCrateImpl;
|
|
||||||
|
|
||||||
/// An handle for the resulting rows of a query.
|
/// An handle for the resulting rows of a query.
|
||||||
pub struct Rows<'stmt> {
|
pub struct Rows<'stmt> {
|
||||||
@ -49,19 +48,12 @@ impl<'stmt> Rows<'stmt> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This trait lets us have "pub(crate)" visibility on some methods. Remove this
|
impl<'stmt> Rows<'stmt> {
|
||||||
// once pub(crate) is stable.
|
pub(crate) fn new(stmt: &'stmt Statement<'stmt>) -> Rows<'stmt> {
|
||||||
pub trait RowsCrateImpl<'stmt> {
|
|
||||||
fn new(stmt: &'stmt Statement<'stmt>) -> Rows<'stmt>;
|
|
||||||
fn get_expected_row<'a>(&'a mut self) -> Result<Row<'a, 'stmt>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'stmt> RowsCrateImpl<'stmt> for Rows<'stmt> {
|
|
||||||
fn new(stmt: &'stmt Statement<'stmt>) -> Rows<'stmt> {
|
|
||||||
Rows { stmt: Some(stmt) }
|
Rows { stmt: Some(stmt) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_expected_row<'a>(&'a mut self) -> Result<Row<'a, 'stmt>> {
|
pub(crate) fn get_expected_row<'a>(&'a mut self) -> Result<Row<'a, 'stmt>> {
|
||||||
match self.next() {
|
match self.next() {
|
||||||
Some(row) => row,
|
Some(row) => row,
|
||||||
None => Err(Error::QueryReturnedNoRows),
|
None => Err(Error::QueryReturnedNoRows),
|
||||||
@ -81,16 +73,10 @@ pub struct MappedRows<'stmt, F> {
|
|||||||
map: F,
|
map: F,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This trait lets us have "pub(crate)" visibility on some methods. Remove this
|
impl<'stmt, T, F> MappedRows<'stmt, F>
|
||||||
// once pub(crate) is stable.
|
|
||||||
pub trait MappedRowsCrateImpl<'stmt, T, F> {
|
|
||||||
fn new(rows: Rows<'stmt>, f: F) -> MappedRows<'stmt, F>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'stmt, T, F> MappedRowsCrateImpl<'stmt, T, F> for MappedRows<'stmt, F>
|
|
||||||
where F: FnMut(&Row) -> T
|
where F: FnMut(&Row) -> T
|
||||||
{
|
{
|
||||||
fn new(rows: Rows<'stmt>, f: F) -> MappedRows<'stmt, F> {
|
pub(crate) fn new(rows: Rows<'stmt>, f: F) -> MappedRows<'stmt, F> {
|
||||||
MappedRows { rows, map: f }
|
MappedRows { rows, map: f }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,16 +101,10 @@ pub struct AndThenRows<'stmt, F> {
|
|||||||
map: F,
|
map: F,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This trait lets us have "pub(crate)" visibility on some methods. Remove this
|
impl<'stmt, T, E, F> AndThenRows<'stmt, F>
|
||||||
// once pub(crate) is stable.
|
|
||||||
pub trait AndThenRowsCrateImpl<'stmt, T, E, F> {
|
|
||||||
fn new(rows: Rows<'stmt>, f: F) -> AndThenRows<'stmt, F>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'stmt, T, E, F> AndThenRowsCrateImpl<'stmt, T, E, F> for AndThenRows<'stmt, F>
|
|
||||||
where F: FnMut(&Row) -> result::Result<T, E>
|
where F: FnMut(&Row) -> result::Result<T, E>
|
||||||
{
|
{
|
||||||
fn new(rows: Rows<'stmt>, f: F) -> AndThenRows<'stmt, F> {
|
pub(crate) fn new(rows: Rows<'stmt>, f: F) -> AndThenRows<'stmt, F> {
|
||||||
AndThenRows { rows, map: f }
|
AndThenRows { rows, map: f }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ use super::ffi;
|
|||||||
use super::{Connection, RawStatement, Result, Error, ValueRef, Row, Rows, AndThenRows, MappedRows};
|
use super::{Connection, RawStatement, Result, Error, ValueRef, Row, Rows, AndThenRows, MappedRows};
|
||||||
use super::str_to_cstring;
|
use super::str_to_cstring;
|
||||||
use types::{ToSql, ToSqlOutput};
|
use types::{ToSql, ToSqlOutput};
|
||||||
use row::{RowsCrateImpl, MappedRowsCrateImpl, AndThenRowsCrateImpl};
|
|
||||||
|
|
||||||
/// A prepared statement.
|
/// A prepared statement.
|
||||||
pub struct Statement<'conn> {
|
pub struct Statement<'conn> {
|
||||||
@ -494,24 +493,15 @@ impl<'conn> Drop for Statement<'conn> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This trait lets us have "pub(crate)" visibility on some Statement methods. Remove this
|
impl<'conn> Statement<'conn> {
|
||||||
// once pub(crate) is stable.
|
pub(crate) fn new(conn: &Connection, stmt: RawStatement) -> Statement {
|
||||||
pub trait StatementCrateImpl<'conn> {
|
|
||||||
fn new(conn: &'conn Connection, stmt: RawStatement) -> Self;
|
|
||||||
fn value_ref(&self, col: usize) -> ValueRef;
|
|
||||||
fn step(&self) -> Result<bool>;
|
|
||||||
fn reset(&self) -> c_int;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> {
|
|
||||||
fn new(conn: &Connection, stmt: RawStatement) -> Statement {
|
|
||||||
Statement {
|
Statement {
|
||||||
conn,
|
conn,
|
||||||
stmt,
|
stmt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn value_ref(&self, col: usize) -> ValueRef {
|
pub(crate) fn value_ref(&self, col: usize) -> ValueRef {
|
||||||
let raw = unsafe { self.stmt.ptr() };
|
let raw = unsafe { self.stmt.ptr() };
|
||||||
|
|
||||||
match self.stmt.column_type(col) {
|
match self.stmt.column_type(col) {
|
||||||
@ -554,7 +544,7 @@ impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn step(&self) -> Result<bool> {
|
pub(crate) fn step(&self) -> Result<bool> {
|
||||||
match self.stmt.step() {
|
match self.stmt.step() {
|
||||||
ffi::SQLITE_ROW => Ok(true),
|
ffi::SQLITE_ROW => Ok(true),
|
||||||
ffi::SQLITE_DONE => Ok(false),
|
ffi::SQLITE_DONE => Ok(false),
|
||||||
@ -562,7 +552,7 @@ impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset(&self) -> c_int {
|
pub(crate) fn reset(&self) -> c_int {
|
||||||
self.stmt.reset()
|
self.stmt.reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user