mirror of
https://github.com/isar/rusqlite.git
synced 2025-09-16 20:52:19 +08:00
Rework ToSql to be implementable without unsafe
.
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
extern crate time;
|
||||
|
||||
use libc::c_int;
|
||||
use {Error, Result};
|
||||
use types::{FromSql, ToSql, ValueRef};
|
||||
|
||||
use ffi::sqlite3_stmt;
|
||||
use types::{FromSql, ToSql, ToSqlOutput, ValueRef};
|
||||
|
||||
const SQLITE_DATETIME_FMT: &'static str = "%Y-%m-%d %H:%M:%S";
|
||||
|
||||
impl ToSql for time::Timespec {
|
||||
unsafe fn bind_parameter(&self, stmt: *mut sqlite3_stmt, col: c_int) -> c_int {
|
||||
let time_str = time::at_utc(*self).strftime(SQLITE_DATETIME_FMT).unwrap().to_string();
|
||||
time_str.bind_parameter(stmt, col)
|
||||
fn to_sql(&self) -> Result<ToSqlOutput> {
|
||||
let time_string = time::at_utc(*self).strftime(SQLITE_DATETIME_FMT).unwrap().to_string();
|
||||
Ok(ToSqlOutput::from(time_string))
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user