Merge branch 'master' into gwenn-invalid-column-type

This commit is contained in:
John Gallagher
2016-12-31 00:35:47 -05:00
21 changed files with 497 additions and 352 deletions

View File

@@ -1,21 +1,19 @@
extern crate time;
use libc::c_int;
use types::{FromSql, FromSqlError, ToSql, ValueRef};
use ffi::sqlite3_stmt;
use Result;
use types::{FromSql, FromSqlError, FromSqlResult, 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))
}
}
impl FromSql for time::Timespec {
fn column_result(value: ValueRef) -> Result<Self, FromSqlError> {
fn column_result(value: ValueRef) -> FromSqlResult<Self> {
value.as_str().and_then(|s| match time::strptime(s, SQLITE_DATETIME_FMT) {
Ok(tm) => Ok(tm.to_timespec()),
Err(err) => Err(FromSqlError::Other(Box::new(err))),