mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 09:09:19 +08:00
Merge remote-tracking branch 'jgallagher/master' into vtab
This commit is contained in:
commit
3aca24792c
@ -93,6 +93,7 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore] // FIXME: unstable
|
||||||
fn test_busy_timeout() {
|
fn test_busy_timeout() {
|
||||||
let temp_dir = TempDir::new("test_busy_timeout").unwrap();
|
let temp_dir = TempDir::new("test_busy_timeout").unwrap();
|
||||||
let path = temp_dir.path().join("test.db3");
|
let path = temp_dir.path().join("test.db3");
|
||||||
@ -121,6 +122,7 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore] // FIXME: unstable
|
||||||
fn test_busy_handler() {
|
fn test_busy_handler() {
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref CALLED: AtomicBool = AtomicBool::new(false);
|
static ref CALLED: AtomicBool = AtomicBool::new(false);
|
||||||
|
@ -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};
|
||||||
@ -997,6 +995,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_concurrent_transactions_busy_commit() {
|
fn test_concurrent_transactions_busy_commit() {
|
||||||
|
use std::time::Duration;
|
||||||
let tmp = TempDir::new("locked").unwrap();
|
let tmp = TempDir::new("locked").unwrap();
|
||||||
let path = tmp.path().join("transactions.db3");
|
let path = tmp.path().join("transactions.db3");
|
||||||
|
|
||||||
@ -1008,8 +1007,8 @@ mod test {
|
|||||||
let mut db1 = Connection::open(&path).unwrap();
|
let mut db1 = Connection::open(&path).unwrap();
|
||||||
let mut db2 = Connection::open(&path).unwrap();
|
let mut db2 = Connection::open(&path).unwrap();
|
||||||
|
|
||||||
db1.execute_batch("PRAGMA busy_timeout = 0;").unwrap();
|
db1.busy_timeout(Duration::from_millis(0)).unwrap();
|
||||||
db2.execute_batch("PRAGMA busy_timeout = 0;").unwrap();
|
db2.busy_timeout(Duration::from_millis(0)).unwrap();
|
||||||
|
|
||||||
{
|
{
|
||||||
let tx1 = db1.transaction().unwrap();
|
let tx1 = db1.transaction().unwrap();
|
||||||
|
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 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,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};
|
|
||||||
#[cfg(feature = "array")]
|
#[cfg(feature = "array")]
|
||||||
use vtab::array::{ARRAY_TYPE, free_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
|
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) {
|
||||||
@ -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() {
|
match self.stmt.step() {
|
||||||
ffi::SQLITE_ROW => Ok(true),
|
ffi::SQLITE_ROW => Ok(true),
|
||||||
ffi::SQLITE_DONE => Ok(false),
|
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()
|
self.stmt.reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,6 @@ pub type SqliteTransaction<'conn> = Transaction<'conn>;
|
|||||||
pub struct Transaction<'conn> {
|
pub struct Transaction<'conn> {
|
||||||
conn: &'conn Connection,
|
conn: &'conn Connection,
|
||||||
drop_behavior: DropBehavior,
|
drop_behavior: DropBehavior,
|
||||||
committed: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a savepoint on a database connection.
|
/// Represents a savepoint on a database connection.
|
||||||
@ -111,7 +110,6 @@ impl<'conn> Transaction<'conn> {
|
|||||||
Transaction {
|
Transaction {
|
||||||
conn,
|
conn,
|
||||||
drop_behavior: DropBehavior::Rollback,
|
drop_behavior: DropBehavior::Rollback,
|
||||||
committed: false,
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -168,7 +166,6 @@ impl<'conn> Transaction<'conn> {
|
|||||||
|
|
||||||
fn commit_(&mut self) -> Result<()> {
|
fn commit_(&mut self) -> Result<()> {
|
||||||
self.conn.execute_batch("COMMIT")?;
|
self.conn.execute_batch("COMMIT")?;
|
||||||
self.committed = true;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +176,6 @@ impl<'conn> Transaction<'conn> {
|
|||||||
|
|
||||||
fn rollback_(&mut self) -> Result<()> {
|
fn rollback_(&mut self) -> Result<()> {
|
||||||
self.conn.execute_batch("ROLLBACK")?;
|
self.conn.execute_batch("ROLLBACK")?;
|
||||||
self.committed = true;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +189,7 @@ impl<'conn> Transaction<'conn> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn finish_(&mut self) -> Result<()> {
|
fn finish_(&mut self) -> Result<()> {
|
||||||
if self.committed {
|
if self.conn.is_autocommit() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
match self.drop_behavior() {
|
match self.drop_behavior() {
|
||||||
|
Loading…
Reference in New Issue
Block a user