mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-26 11:31:37 +08:00
Rename SqliteTransaction*
-> Transaction*
.
This commit is contained in:
parent
9cac56d6a2
commit
3d15a8a15c
@ -8,7 +8,9 @@
|
|||||||
* `SqliteRows` is now `Rows`
|
* `SqliteRows` is now `Rows`
|
||||||
* `SqliteRow` is now `Row`
|
* `SqliteRow` is now `Row`
|
||||||
* `SqliteOpenFlags` is now `OpenFlags`
|
* `SqliteOpenFlags` is now `OpenFlags`
|
||||||
The old, prefixed names are still exported should be considered deprecated.
|
* `SqliteTransaction` is now `Transaction`.
|
||||||
|
* `SqliteTransactionBehavior` is now `TransactionBehavior`.
|
||||||
|
The old, prefixed names are still exported but are deprecated.
|
||||||
* Adds a variety of `..._named` methods for executing queries using named placeholder parameters.
|
* Adds a variety of `..._named` methods for executing queries using named placeholder parameters.
|
||||||
* Adds `backup` feature that exposes SQLite's online backup API.
|
* Adds `backup` feature that exposes SQLite's online backup API.
|
||||||
* Adds `functions` feature that allows user-defined scalar functions to be added to
|
* Adds `functions` feature that allows user-defined scalar functions to be added to
|
||||||
|
16
src/lib.rs
16
src/lib.rs
@ -74,9 +74,9 @@ use libc::{c_int, c_void, c_char};
|
|||||||
|
|
||||||
use types::{ToSql, FromSql};
|
use types::{ToSql, FromSql};
|
||||||
|
|
||||||
pub use transaction::SqliteTransaction;
|
pub use transaction::Transaction;
|
||||||
pub use transaction::{SqliteTransactionBehavior, SqliteTransactionDeferred,
|
pub use transaction::{TransactionBehavior, TransactionDeferred,
|
||||||
SqliteTransactionImmediate, SqliteTransactionExclusive};
|
TransactionImmediate, TransactionExclusive};
|
||||||
|
|
||||||
#[cfg(feature = "load_extension")]
|
#[cfg(feature = "load_extension")]
|
||||||
pub use load_extension_guard::SqliteLoadExtensionGuard;
|
pub use load_extension_guard::SqliteLoadExtensionGuard;
|
||||||
@ -285,8 +285,8 @@ impl Connection {
|
|||||||
/// # Failure
|
/// # Failure
|
||||||
///
|
///
|
||||||
/// Will return `Err` if the underlying SQLite call fails.
|
/// Will return `Err` if the underlying SQLite call fails.
|
||||||
pub fn transaction<'a>(&'a self) -> Result<SqliteTransaction<'a>> {
|
pub fn transaction<'a>(&'a self) -> Result<Transaction<'a>> {
|
||||||
SqliteTransaction::new(self, SqliteTransactionDeferred)
|
Transaction::new(self, TransactionDeferred)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Begin a new transaction with a specified behavior.
|
/// Begin a new transaction with a specified behavior.
|
||||||
@ -297,9 +297,9 @@ impl Connection {
|
|||||||
///
|
///
|
||||||
/// Will return `Err` if the underlying SQLite call fails.
|
/// Will return `Err` if the underlying SQLite call fails.
|
||||||
pub fn transaction_with_behavior<'a>(&'a self,
|
pub fn transaction_with_behavior<'a>(&'a self,
|
||||||
behavior: SqliteTransactionBehavior)
|
behavior: TransactionBehavior)
|
||||||
-> Result<SqliteTransaction<'a>> {
|
-> Result<Transaction<'a>> {
|
||||||
SqliteTransaction::new(self, behavior)
|
Transaction::new(self, behavior)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to run multiple SQL statements (that cannot take any parameters).
|
/// Convenience method to run multiple SQL statements (that cannot take any parameters).
|
||||||
|
@ -1,17 +1,23 @@
|
|||||||
use {Result, Connection};
|
use {Result, Connection};
|
||||||
|
|
||||||
pub use SqliteTransactionBehavior::{SqliteTransactionDeferred, SqliteTransactionImmediate,
|
pub use TransactionBehavior::{TransactionDeferred, TransactionImmediate, TransactionExclusive};
|
||||||
SqliteTransactionExclusive};
|
|
||||||
|
/// Old name for `TransactionBehavior`. `SqliteTransactionBehavior` is deprecated.
|
||||||
|
pub type SqliteTransactionBehavior = TransactionBehavior;
|
||||||
|
|
||||||
/// Options for transaction behavior. See [BEGIN
|
/// Options for transaction behavior. See [BEGIN
|
||||||
/// TRANSACTION](http://www.sqlite.org/lang_transaction.html) for details.
|
/// TRANSACTION](http://www.sqlite.org/lang_transaction.html) for details.
|
||||||
#[derive(Copy,Clone)]
|
#[derive(Copy,Clone)]
|
||||||
pub enum SqliteTransactionBehavior {
|
pub enum TransactionBehavior {
|
||||||
SqliteTransactionDeferred,
|
TransactionDeferred,
|
||||||
SqliteTransactionImmediate,
|
TransactionImmediate,
|
||||||
SqliteTransactionExclusive,
|
TransactionExclusive,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Old name for `Transaction`. `SqliteTransaction` is deprecated.
|
||||||
|
pub type SqliteTransaction<'conn> = Transaction<'conn>;
|
||||||
|
|
||||||
|
///
|
||||||
/// Represents a transaction on a database connection.
|
/// Represents a transaction on a database connection.
|
||||||
///
|
///
|
||||||
/// ## Note
|
/// ## Note
|
||||||
@ -34,25 +40,25 @@ pub enum SqliteTransactionBehavior {
|
|||||||
/// tx.commit()
|
/// tx.commit()
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub struct SqliteTransaction<'conn> {
|
pub struct Transaction<'conn> {
|
||||||
conn: &'conn Connection,
|
conn: &'conn Connection,
|
||||||
depth: u32,
|
depth: u32,
|
||||||
commit: bool,
|
commit: bool,
|
||||||
finished: bool,
|
finished: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'conn> SqliteTransaction<'conn> {
|
impl<'conn> Transaction<'conn> {
|
||||||
/// Begin a new transaction. Cannot be nested; see `savepoint` for nested transactions.
|
/// Begin a new transaction. Cannot be nested; see `savepoint` for nested transactions.
|
||||||
pub fn new(conn: &Connection,
|
pub fn new(conn: &Connection,
|
||||||
behavior: SqliteTransactionBehavior)
|
behavior: TransactionBehavior)
|
||||||
-> Result<SqliteTransaction> {
|
-> Result<Transaction> {
|
||||||
let query = match behavior {
|
let query = match behavior {
|
||||||
SqliteTransactionDeferred => "BEGIN DEFERRED",
|
TransactionDeferred => "BEGIN DEFERRED",
|
||||||
SqliteTransactionImmediate => "BEGIN IMMEDIATE",
|
TransactionImmediate => "BEGIN IMMEDIATE",
|
||||||
SqliteTransactionExclusive => "BEGIN EXCLUSIVE",
|
TransactionExclusive => "BEGIN EXCLUSIVE",
|
||||||
};
|
};
|
||||||
conn.execute_batch(query).map(|_| {
|
conn.execute_batch(query).map(|_| {
|
||||||
SqliteTransaction {
|
Transaction {
|
||||||
conn: conn,
|
conn: conn,
|
||||||
depth: 0,
|
depth: 0,
|
||||||
commit: false,
|
commit: false,
|
||||||
@ -87,9 +93,9 @@ impl<'conn> SqliteTransaction<'conn> {
|
|||||||
/// tx.commit()
|
/// tx.commit()
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn savepoint<'a>(&'a self) -> Result<SqliteTransaction<'a>> {
|
pub fn savepoint<'a>(&'a self) -> Result<Transaction<'a>> {
|
||||||
self.conn.execute_batch("SAVEPOINT sp").map(|_| {
|
self.conn.execute_batch("SAVEPOINT sp").map(|_| {
|
||||||
SqliteTransaction {
|
Transaction {
|
||||||
conn: self.conn,
|
conn: self.conn,
|
||||||
depth: self.depth + 1,
|
depth: self.depth + 1,
|
||||||
commit: false,
|
commit: false,
|
||||||
@ -165,7 +171,7 @@ impl<'conn> SqliteTransaction<'conn> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_must_use)]
|
#[allow(unused_must_use)]
|
||||||
impl<'conn> Drop for SqliteTransaction<'conn> {
|
impl<'conn> Drop for Transaction<'conn> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.finish_();
|
self.finish_();
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ pub trait FromSql: Sized {
|
|||||||
|
|
||||||
/// FromSql types can implement this method and use sqlite3_column_type to check that
|
/// FromSql types can implement this method and use sqlite3_column_type to check that
|
||||||
/// the type reported by SQLite matches a type suitable for Self. This method is used
|
/// the type reported by SQLite matches a type suitable for Self. This method is used
|
||||||
/// by `SqliteRow::get_checked` to confirm that the column contains a valid type before
|
/// by `Row::get_checked` to confirm that the column contains a valid type before
|
||||||
/// attempting to retrieve the value.
|
/// attempting to retrieve the value.
|
||||||
unsafe fn column_has_valid_sqlite_type(_: *mut sqlite3_stmt, _: c_int) -> bool {
|
unsafe fn column_has_valid_sqlite_type(_: *mut sqlite3_stmt, _: c_int) -> bool {
|
||||||
true
|
true
|
||||||
|
Loading…
Reference in New Issue
Block a user