diff --git a/src/lib.rs b/src/lib.rs index 530cfc0..eb96b11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,7 +58,7 @@ use std::default::Default; use std::mem; use std::ptr; use std::fmt; -use std::path::{Path}; +use std::path::{Path,PathBuf}; use std::error; use std::rc::{Rc}; use std::cell::{RefCell, Cell}; @@ -151,6 +151,7 @@ fn path_to_cstring(p: &Path) -> SqliteResult { /// prepare multiple statements at the same time). pub struct SqliteConnection { db: RefCell, + path: Option, } unsafe impl Send for SqliteConnection {} @@ -179,7 +180,7 @@ impl SqliteConnection { -> SqliteResult { let c_path = try!(path_to_cstring(path.as_ref())); InnerSqliteConnection::open_with_flags(&c_path, flags).map(|db| { - SqliteConnection{ db: RefCell::new(db) } + SqliteConnection{ db: RefCell::new(db), path: Some(path.as_ref().to_path_buf()) } }) } @@ -190,7 +191,7 @@ impl SqliteConnection { pub fn open_in_memory_with_flags(flags: SqliteOpenFlags) -> SqliteResult { let c_memory = try!(str_to_cstring(":memory:")); InnerSqliteConnection::open_with_flags(&c_memory, flags).map(|db| { - SqliteConnection{ db: RefCell::new(db) } + SqliteConnection{ db: RefCell::new(db), path: None } }) } @@ -411,7 +412,7 @@ impl SqliteConnection { impl fmt::Debug for SqliteConnection { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "SqliteConnection()") + write!(f, "SqliteConnection( path: {:?} )", &self.path) } } @@ -673,7 +674,7 @@ impl<'conn> SqliteStatement<'conn> { } /// Executes the prepared statement and maps a function over the resulting - /// rows. + /// rows. /// /// Unlike the iterator produced by `query`, the returned iterator does not expose the possibility /// for accessing stale rows. @@ -728,7 +729,11 @@ impl<'conn> SqliteStatement<'conn> { impl<'conn> fmt::Debug for SqliteStatement<'conn> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Statement( conn: {:?}, stmt: {:?} )", self.conn, self.stmt) + let sql = unsafe { + let c_slice = CStr::from_ptr(ffi::sqlite3_sql(self.stmt)).to_bytes(); + str::from_utf8(c_slice) + }; + write!(f, "SqliteStatement( conn: {:?}, stmt: {:?}, sql: {:?} )", self.conn, self.stmt, sql) } }