Rename SqliteTransaction* -> Transaction*.

This commit is contained in:
John Gallagher 2015-12-12 14:17:43 -05:00
parent 9cac56d6a2
commit 3d15a8a15c
4 changed files with 35 additions and 27 deletions

View File

@ -8,7 +8,9 @@
* `SqliteRows` is now `Rows`
* `SqliteRow` is now `Row`
* `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 `backup` feature that exposes SQLite's online backup API.
* Adds `functions` feature that allows user-defined scalar functions to be added to

View File

@ -74,9 +74,9 @@ use libc::{c_int, c_void, c_char};
use types::{ToSql, FromSql};
pub use transaction::SqliteTransaction;
pub use transaction::{SqliteTransactionBehavior, SqliteTransactionDeferred,
SqliteTransactionImmediate, SqliteTransactionExclusive};
pub use transaction::Transaction;
pub use transaction::{TransactionBehavior, TransactionDeferred,
TransactionImmediate, TransactionExclusive};
#[cfg(feature = "load_extension")]
pub use load_extension_guard::SqliteLoadExtensionGuard;
@ -285,8 +285,8 @@ impl Connection {
/// # Failure
///
/// Will return `Err` if the underlying SQLite call fails.
pub fn transaction<'a>(&'a self) -> Result<SqliteTransaction<'a>> {
SqliteTransaction::new(self, SqliteTransactionDeferred)
pub fn transaction<'a>(&'a self) -> Result<Transaction<'a>> {
Transaction::new(self, TransactionDeferred)
}
/// Begin a new transaction with a specified behavior.
@ -297,9 +297,9 @@ impl Connection {
///
/// Will return `Err` if the underlying SQLite call fails.
pub fn transaction_with_behavior<'a>(&'a self,
behavior: SqliteTransactionBehavior)
-> Result<SqliteTransaction<'a>> {
SqliteTransaction::new(self, behavior)
behavior: TransactionBehavior)
-> Result<Transaction<'a>> {
Transaction::new(self, behavior)
}
/// Convenience method to run multiple SQL statements (that cannot take any parameters).

View File

@ -1,17 +1,23 @@
use {Result, Connection};
pub use SqliteTransactionBehavior::{SqliteTransactionDeferred, SqliteTransactionImmediate,
SqliteTransactionExclusive};
pub use TransactionBehavior::{TransactionDeferred, TransactionImmediate, TransactionExclusive};
/// Old name for `TransactionBehavior`. `SqliteTransactionBehavior` is deprecated.
pub type SqliteTransactionBehavior = TransactionBehavior;
/// Options for transaction behavior. See [BEGIN
/// TRANSACTION](http://www.sqlite.org/lang_transaction.html) for details.
#[derive(Copy,Clone)]
pub enum SqliteTransactionBehavior {
SqliteTransactionDeferred,
SqliteTransactionImmediate,
SqliteTransactionExclusive,
pub enum TransactionBehavior {
TransactionDeferred,
TransactionImmediate,
TransactionExclusive,
}
/// Old name for `Transaction`. `SqliteTransaction` is deprecated.
pub type SqliteTransaction<'conn> = Transaction<'conn>;
///
/// Represents a transaction on a database connection.
///
/// ## Note
@ -34,25 +40,25 @@ pub enum SqliteTransactionBehavior {
/// tx.commit()
/// }
/// ```
pub struct SqliteTransaction<'conn> {
pub struct Transaction<'conn> {
conn: &'conn Connection,
depth: u32,
commit: bool,
finished: bool,
}
impl<'conn> SqliteTransaction<'conn> {
impl<'conn> Transaction<'conn> {
/// Begin a new transaction. Cannot be nested; see `savepoint` for nested transactions.
pub fn new(conn: &Connection,
behavior: SqliteTransactionBehavior)
-> Result<SqliteTransaction> {
behavior: TransactionBehavior)
-> Result<Transaction> {
let query = match behavior {
SqliteTransactionDeferred => "BEGIN DEFERRED",
SqliteTransactionImmediate => "BEGIN IMMEDIATE",
SqliteTransactionExclusive => "BEGIN EXCLUSIVE",
TransactionDeferred => "BEGIN DEFERRED",
TransactionImmediate => "BEGIN IMMEDIATE",
TransactionExclusive => "BEGIN EXCLUSIVE",
};
conn.execute_batch(query).map(|_| {
SqliteTransaction {
Transaction {
conn: conn,
depth: 0,
commit: false,
@ -87,9 +93,9 @@ impl<'conn> SqliteTransaction<'conn> {
/// 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(|_| {
SqliteTransaction {
Transaction {
conn: self.conn,
depth: self.depth + 1,
commit: false,
@ -165,7 +171,7 @@ impl<'conn> SqliteTransaction<'conn> {
}
#[allow(unused_must_use)]
impl<'conn> Drop for SqliteTransaction<'conn> {
impl<'conn> Drop for Transaction<'conn> {
fn drop(&mut self) {
self.finish_();
}

View File

@ -79,7 +79,7 @@ pub trait FromSql: Sized {
/// 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
/// 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.
unsafe fn column_has_valid_sqlite_type(_: *mut sqlite3_stmt, _: c_int) -> bool {
true