mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +08:00
Merge pull request #370 from gwenn/tx
Use `sqlite3_get_autocommit` instead of our own flag/status
This commit is contained in:
commit
be6ea9b665
@ -993,6 +993,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");
|
||||||
|
|
||||||
@ -1004,8 +1005,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();
|
||||||
|
@ -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