Rename SqliteStatement -> Statement.

This commit is contained in:
John Gallagher 2015-12-12 14:08:04 -05:00
parent eb60bb3111
commit ec654352d9
3 changed files with 19 additions and 16 deletions

View File

@ -4,6 +4,7 @@
* `SqliteConnection` is now `Connection` * `SqliteConnection` is now `Connection`
* `SqliteError` is now `Error` * `SqliteError` is now `Error`
* `SqliteResult` is now `Result` * `SqliteResult` is now `Result`
* `SqliteStatement` is now `Statement`
The old, prefixed names are still exported should be considered deprecated. The old, prefixed names are still exported should be considered 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.

View File

@ -461,7 +461,7 @@ impl Connection {
/// ///
/// Will return `Err` if `sql` cannot be converted to a C-compatible string or if the /// Will return `Err` if `sql` cannot be converted to a C-compatible string or if the
/// underlying SQLite call fails. /// underlying SQLite call fails.
pub fn prepare<'a>(&'a self, sql: &str) -> Result<SqliteStatement<'a>> { pub fn prepare<'a>(&'a self, sql: &str) -> Result<Statement<'a>> {
self.db.borrow_mut().prepare(self, sql) self.db.borrow_mut().prepare(self, sql)
} }
@ -698,7 +698,7 @@ impl InnerConnection {
fn prepare<'a>(&mut self, fn prepare<'a>(&mut self,
conn: &'a Connection, conn: &'a Connection,
sql: &str) sql: &str)
-> Result<SqliteStatement<'a>> { -> Result<Statement<'a>> {
if sql.len() >= ::std::i32::MAX as usize { if sql.len() >= ::std::i32::MAX as usize {
return Err(Error { return Err(Error {
code: ffi::SQLITE_TOOBIG, code: ffi::SQLITE_TOOBIG,
@ -715,7 +715,7 @@ impl InnerConnection {
&mut c_stmt, &mut c_stmt,
ptr::null_mut()) ptr::null_mut())
}; };
self.decode_result(r).map(|_| SqliteStatement::new(conn, c_stmt)) self.decode_result(r).map(|_| Statement::new(conn, c_stmt))
} }
fn changes(&mut self) -> c_int { fn changes(&mut self) -> c_int {
@ -730,17 +730,20 @@ impl Drop for InnerConnection {
} }
} }
/// Old name for `Statement`. `SqliteStatement` is deprecated.
pub type SqliteStatement<'conn> = Statement<'conn>;
/// A prepared statement. /// A prepared statement.
pub struct SqliteStatement<'conn> { pub struct Statement<'conn> {
conn: &'conn Connection, conn: &'conn Connection,
stmt: *mut ffi::sqlite3_stmt, stmt: *mut ffi::sqlite3_stmt,
needs_reset: bool, needs_reset: bool,
column_count: c_int, column_count: c_int,
} }
impl<'conn> SqliteStatement<'conn> { impl<'conn> Statement<'conn> {
fn new(conn: &Connection, stmt: *mut ffi::sqlite3_stmt) -> SqliteStatement { fn new(conn: &Connection, stmt: *mut ffi::sqlite3_stmt) -> Statement {
SqliteStatement { Statement {
conn: conn, conn: conn,
stmt: stmt, stmt: stmt,
needs_reset: false, needs_reset: false,
@ -938,13 +941,13 @@ impl<'conn> SqliteStatement<'conn> {
} }
} }
impl<'conn> fmt::Debug for SqliteStatement<'conn> { impl<'conn> fmt::Debug for Statement<'conn> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let sql = unsafe { let sql = unsafe {
let c_slice = CStr::from_ptr(ffi::sqlite3_sql(self.stmt)).to_bytes(); let c_slice = CStr::from_ptr(ffi::sqlite3_sql(self.stmt)).to_bytes();
str::from_utf8(c_slice) str::from_utf8(c_slice)
}; };
f.debug_struct("SqliteStatement") f.debug_struct("Statement")
.field("conn", self.conn) .field("conn", self.conn)
.field("stmt", &self.stmt) .field("stmt", &self.stmt)
.field("sql", &sql) .field("sql", &sql)
@ -952,7 +955,7 @@ impl<'conn> fmt::Debug for SqliteStatement<'conn> {
} }
} }
impl<'conn> Drop for SqliteStatement<'conn> { impl<'conn> Drop for Statement<'conn> {
#[allow(unused_must_use)] #[allow(unused_must_use)]
fn drop(&mut self) { fn drop(&mut self) {
self.finalize_(); self.finalize_();
@ -1031,13 +1034,13 @@ where E: convert::From<Error>,
/// functions which are useful (such as support for `for ... in ...` looping, `map`, `filter`, /// functions which are useful (such as support for `for ... in ...` looping, `map`, `filter`,
/// etc.). /// etc.).
pub struct SqliteRows<'stmt> { pub struct SqliteRows<'stmt> {
stmt: &'stmt SqliteStatement<'stmt>, stmt: &'stmt Statement<'stmt>,
current_row: Rc<Cell<c_int>>, current_row: Rc<Cell<c_int>>,
failed: bool, failed: bool,
} }
impl<'stmt> SqliteRows<'stmt> { impl<'stmt> SqliteRows<'stmt> {
fn new(stmt: &'stmt SqliteStatement<'stmt>) -> SqliteRows<'stmt> { fn new(stmt: &'stmt Statement<'stmt>) -> SqliteRows<'stmt> {
SqliteRows { SqliteRows {
stmt: stmt, stmt: stmt,
current_row: Rc::new(Cell::new(0)), current_row: Rc::new(Cell::new(0)),
@ -1086,7 +1089,7 @@ impl<'stmt> Iterator for SqliteRows<'stmt> {
/// A single result row of a query. /// A single result row of a query.
pub struct SqliteRow<'stmt> { pub struct SqliteRow<'stmt> {
stmt: &'stmt SqliteStatement<'stmt>, stmt: &'stmt Statement<'stmt>,
current_row: Rc<Cell<c_int>>, current_row: Rc<Cell<c_int>>,
row_idx: c_int, row_idx: c_int,
} }

View File

@ -2,8 +2,7 @@ use libc::c_int;
use super::ffi; use super::ffi;
use {Result, Error, Connection, SqliteStatement, SqliteRows, SqliteRow, use {Result, Error, Connection, Statement, SqliteRows, SqliteRow, str_to_cstring};
str_to_cstring};
use types::ToSql; use types::ToSql;
impl Connection { impl Connection {
@ -52,7 +51,7 @@ impl Connection {
} }
} }
impl<'conn> SqliteStatement<'conn> { impl<'conn> Statement<'conn> {
/// Return the index of an SQL parameter given its name. /// Return the index of an SQL parameter given its name.
/// ///
/// # Failure /// # Failure