mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-26 11:31:37 +08:00
Debug db path and stmt sql.
This commit is contained in:
parent
36f577aea6
commit
05669082a3
15
src/lib.rs
15
src/lib.rs
@ -58,7 +58,7 @@ use std::default::Default;
|
|||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::path::{Path};
|
use std::path::{Path,PathBuf};
|
||||||
use std::error;
|
use std::error;
|
||||||
use std::rc::{Rc};
|
use std::rc::{Rc};
|
||||||
use std::cell::{RefCell, Cell};
|
use std::cell::{RefCell, Cell};
|
||||||
@ -151,6 +151,7 @@ fn path_to_cstring(p: &Path) -> SqliteResult<CString> {
|
|||||||
/// prepare multiple statements at the same time).
|
/// prepare multiple statements at the same time).
|
||||||
pub struct SqliteConnection {
|
pub struct SqliteConnection {
|
||||||
db: RefCell<InnerSqliteConnection>,
|
db: RefCell<InnerSqliteConnection>,
|
||||||
|
path: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for SqliteConnection {}
|
unsafe impl Send for SqliteConnection {}
|
||||||
@ -179,7 +180,7 @@ impl SqliteConnection {
|
|||||||
-> SqliteResult<SqliteConnection> {
|
-> SqliteResult<SqliteConnection> {
|
||||||
let c_path = try!(path_to_cstring(path.as_ref()));
|
let c_path = try!(path_to_cstring(path.as_ref()));
|
||||||
InnerSqliteConnection::open_with_flags(&c_path, flags).map(|db| {
|
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<SqliteConnection> {
|
pub fn open_in_memory_with_flags(flags: SqliteOpenFlags) -> SqliteResult<SqliteConnection> {
|
||||||
let c_memory = try!(str_to_cstring(":memory:"));
|
let c_memory = try!(str_to_cstring(":memory:"));
|
||||||
InnerSqliteConnection::open_with_flags(&c_memory, flags).map(|db| {
|
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 {
|
impl fmt::Debug for SqliteConnection {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "SqliteConnection()")
|
write!(f, "SqliteConnection( path: {:?} )", &self.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -728,7 +729,11 @@ impl<'conn> SqliteStatement<'conn> {
|
|||||||
|
|
||||||
impl<'conn> fmt::Debug for SqliteStatement<'conn> {
|
impl<'conn> fmt::Debug for SqliteStatement<'conn> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user