Merge remote-tracking branch 'jgallagher/master' into vtab

This commit is contained in:
gwenn 2018-08-05 13:26:45 +02:00
commit 3aca24792c
6 changed files with 18 additions and 52 deletions

View File

@ -93,6 +93,7 @@ mod test {
}
#[test]
#[ignore] // FIXME: unstable
fn test_busy_timeout() {
let temp_dir = TempDir::new("test_busy_timeout").unwrap();
let path = temp_dir.path().join("test.db3");
@ -121,6 +122,7 @@ mod test {
}
#[test]
#[ignore] // FIXME: unstable
fn test_busy_handler() {
lazy_static! {
static ref CALLED: AtomicBool = AtomicBool::new(false);

View File

@ -5,7 +5,6 @@ use std::ops::{Deref, DerefMut};
use lru_cache::LruCache;
use {Result, Connection, Statement};
use raw_statement::RawStatement;
use statement::StatementCrateImpl;
impl Connection {
/// Prepare a SQL statement for execution, returning a previously prepared (but

View File

@ -80,10 +80,8 @@ use raw_statement::RawStatement;
use cache::StatementCache;
pub use statement::Statement;
use statement::StatementCrateImpl;
pub use row::{Row, Rows, MappedRows, AndThenRows, RowIndex};
use row::RowsCrateImpl;
#[allow(deprecated)]
pub use transaction::{SqliteTransaction, SqliteTransactionBehavior};
@ -997,6 +995,7 @@ mod test {
#[test]
fn test_concurrent_transactions_busy_commit() {
use std::time::Duration;
let tmp = TempDir::new("locked").unwrap();
let path = tmp.path().join("transactions.db3");
@ -1008,8 +1007,8 @@ mod test {
let mut db1 = Connection::open(&path).unwrap();
let mut db2 = Connection::open(&path).unwrap();
db1.execute_batch("PRAGMA busy_timeout = 0;").unwrap();
db2.execute_batch("PRAGMA busy_timeout = 0;").unwrap();
db1.busy_timeout(Duration::from_millis(0)).unwrap();
db2.busy_timeout(Duration::from_millis(0)).unwrap();
{
let tx1 = db1.transaction().unwrap();

View File

@ -3,7 +3,6 @@ use std::marker::PhantomData;
use super::{Statement, Error, Result};
use types::{FromSql, FromSqlError};
use statement::StatementCrateImpl;
/// An handle for the resulting rows of a query.
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
// once pub(crate) is stable.
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> {
impl<'stmt> Rows<'stmt> {
pub(crate) fn new(stmt: &'stmt Statement<'stmt>) -> Rows<'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() {
Some(row) => row,
None => Err(Error::QueryReturnedNoRows),
@ -81,16 +73,10 @@ pub struct MappedRows<'stmt, F> {
map: F,
}
// TODO: This trait lets us have "pub(crate)" visibility on some methods. Remove this
// 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>
impl<'stmt, T, F> MappedRows<'stmt, F>
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 }
}
}
@ -115,16 +101,10 @@ pub struct AndThenRows<'stmt, F> {
map: F,
}
// TODO: This trait lets us have "pub(crate)" visibility on some methods. Remove this
// 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>
impl<'stmt, T, E, F> AndThenRows<'stmt, F>
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 }
}
}

View File

@ -9,7 +9,6 @@ use super::ffi;
use super::{Connection, RawStatement, Result, Error, ValueRef, Row, Rows, AndThenRows, MappedRows};
use super::str_to_cstring;
use types::{ToSql, ToSqlOutput};
use row::{RowsCrateImpl, MappedRowsCrateImpl, AndThenRowsCrateImpl};
#[cfg(feature = "array")]
use vtab::array::{ARRAY_TYPE, free_array};
@ -503,24 +502,15 @@ impl<'conn> Drop for Statement<'conn> {
}
}
// TODO: This trait lets us have "pub(crate)" visibility on some Statement methods. Remove this
// once pub(crate) is stable.
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 {
impl<'conn> Statement<'conn> {
pub(crate) fn new(conn: &Connection, stmt: RawStatement) -> Statement {
Statement {
conn,
stmt,
}
}
fn value_ref(&self, col: usize) -> ValueRef {
pub(crate) fn value_ref(&self, col: usize) -> ValueRef {
let raw = unsafe { self.stmt.ptr() };
match self.stmt.column_type(col) {
@ -563,7 +553,7 @@ impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> {
}
}
fn step(&self) -> Result<bool> {
pub(crate) fn step(&self) -> Result<bool> {
match self.stmt.step() {
ffi::SQLITE_ROW => Ok(true),
ffi::SQLITE_DONE => Ok(false),
@ -571,7 +561,7 @@ impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> {
}
}
fn reset(&self) -> c_int {
pub(crate) fn reset(&self) -> c_int {
self.stmt.reset()
}
}

View File

@ -61,7 +61,6 @@ pub type SqliteTransaction<'conn> = Transaction<'conn>;
pub struct Transaction<'conn> {
conn: &'conn Connection,
drop_behavior: DropBehavior,
committed: bool,
}
/// Represents a savepoint on a database connection.
@ -111,7 +110,6 @@ impl<'conn> Transaction<'conn> {
Transaction {
conn,
drop_behavior: DropBehavior::Rollback,
committed: false,
}
})
}
@ -168,7 +166,6 @@ impl<'conn> Transaction<'conn> {
fn commit_(&mut self) -> Result<()> {
self.conn.execute_batch("COMMIT")?;
self.committed = true;
Ok(())
}
@ -179,7 +176,6 @@ impl<'conn> Transaction<'conn> {
fn rollback_(&mut self) -> Result<()> {
self.conn.execute_batch("ROLLBACK")?;
self.committed = true;
Ok(())
}
@ -193,7 +189,7 @@ impl<'conn> Transaction<'conn> {
}
fn finish_(&mut self) -> Result<()> {
if self.committed {
if self.conn.is_autocommit() {
return Ok(());
}
match self.drop_behavior() {