From ec654352d97facaad7f7e2957968e0ba6caf56af Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Sat, 12 Dec 2015 14:08:04 -0500 Subject: [PATCH] Rename `SqliteStatement` -> `Statement`. --- Changelog.md | 1 + src/lib.rs | 29 ++++++++++++++++------------- src/named_params.rs | 5 ++--- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Changelog.md b/Changelog.md index e9d7d56..bbb595a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,7 @@ * `SqliteConnection` is now `Connection` * `SqliteError` is now `Error` * `SqliteResult` is now `Result` + * `SqliteStatement` is now `Statement` 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 `backup` feature that exposes SQLite's online backup API. diff --git a/src/lib.rs b/src/lib.rs index eb43b04..b3c4a67 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -461,7 +461,7 @@ impl Connection { /// /// Will return `Err` if `sql` cannot be converted to a C-compatible string or if the /// underlying SQLite call fails. - pub fn prepare<'a>(&'a self, sql: &str) -> Result> { + pub fn prepare<'a>(&'a self, sql: &str) -> Result> { self.db.borrow_mut().prepare(self, sql) } @@ -698,7 +698,7 @@ impl InnerConnection { fn prepare<'a>(&mut self, conn: &'a Connection, sql: &str) - -> Result> { + -> Result> { if sql.len() >= ::std::i32::MAX as usize { return Err(Error { code: ffi::SQLITE_TOOBIG, @@ -715,7 +715,7 @@ impl InnerConnection { &mut c_stmt, 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 { @@ -730,17 +730,20 @@ impl Drop for InnerConnection { } } +/// Old name for `Statement`. `SqliteStatement` is deprecated. +pub type SqliteStatement<'conn> = Statement<'conn>; + /// A prepared statement. -pub struct SqliteStatement<'conn> { +pub struct Statement<'conn> { conn: &'conn Connection, stmt: *mut ffi::sqlite3_stmt, needs_reset: bool, column_count: c_int, } -impl<'conn> SqliteStatement<'conn> { - fn new(conn: &Connection, stmt: *mut ffi::sqlite3_stmt) -> SqliteStatement { - SqliteStatement { +impl<'conn> Statement<'conn> { + fn new(conn: &Connection, stmt: *mut ffi::sqlite3_stmt) -> Statement { + Statement { conn: conn, stmt: stmt, 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 { let sql = unsafe { let c_slice = CStr::from_ptr(ffi::sqlite3_sql(self.stmt)).to_bytes(); str::from_utf8(c_slice) }; - f.debug_struct("SqliteStatement") + f.debug_struct("Statement") .field("conn", self.conn) .field("stmt", &self.stmt) .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)] fn drop(&mut self) { self.finalize_(); @@ -1031,13 +1034,13 @@ where E: convert::From, /// functions which are useful (such as support for `for ... in ...` looping, `map`, `filter`, /// etc.). pub struct SqliteRows<'stmt> { - stmt: &'stmt SqliteStatement<'stmt>, + stmt: &'stmt Statement<'stmt>, current_row: Rc>, failed: bool, } impl<'stmt> SqliteRows<'stmt> { - fn new(stmt: &'stmt SqliteStatement<'stmt>) -> SqliteRows<'stmt> { + fn new(stmt: &'stmt Statement<'stmt>) -> SqliteRows<'stmt> { SqliteRows { stmt: stmt, current_row: Rc::new(Cell::new(0)), @@ -1086,7 +1089,7 @@ impl<'stmt> Iterator for SqliteRows<'stmt> { /// A single result row of a query. pub struct SqliteRow<'stmt> { - stmt: &'stmt SqliteStatement<'stmt>, + stmt: &'stmt Statement<'stmt>, current_row: Rc>, row_idx: c_int, } diff --git a/src/named_params.rs b/src/named_params.rs index 9dd08a2..64d8bf1 100644 --- a/src/named_params.rs +++ b/src/named_params.rs @@ -2,8 +2,7 @@ use libc::c_int; use super::ffi; -use {Result, Error, Connection, SqliteStatement, SqliteRows, SqliteRow, - str_to_cstring}; +use {Result, Error, Connection, Statement, SqliteRows, SqliteRow, str_to_cstring}; use types::ToSql; 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. /// /// # Failure