Rework ToSql to be implementable without unsafe.

This commit is contained in:
John Gallagher
2016-05-25 22:57:43 -04:00
parent 9e49452300
commit e4926ac0d7
10 changed files with 206 additions and 122 deletions

View File

@@ -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))
}
}