From 3a178d6d17257778a6df0b2e44a8a4a12e807580 Mon Sep 17 00:00:00 2001 From: gwenn Date: Thu, 22 Nov 2018 16:43:19 +0100 Subject: [PATCH 1/3] Check chrono FromSql implementations Make sure SQLite built-in CURRENT_DATE/TIME/TIMESTAMP output is supported. --- src/types/chrono.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/types/chrono.rs b/src/types/chrono.rs index f5a8cbc..2835f92 100644 --- a/src/types/chrono.rs +++ b/src/types/chrono.rs @@ -132,7 +132,7 @@ mod test { use super::chrono::{ DateTime, Duration, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc, }; - use {Connection, NO_PARAMS}; + use {Connection, Result, NO_PARAMS}; fn checked_memory_handle() -> Connection { let db = Connection::open_in_memory().unwrap(); @@ -263,4 +263,21 @@ mod test { .unwrap(); assert_eq!(local, v); } + + #[test] + fn test_sqlite_functions() { + let db = checked_memory_handle(); + let result: Result = + db.query_row("SELECT CURRENT_TIME", NO_PARAMS, |r| r.get(0)); + assert!(result.is_ok()); + let result: Result = + db.query_row("SELECT CURRENT_DATE", NO_PARAMS, |r| r.get(0)); + assert!(result.is_ok()); + let result: Result = + db.query_row("SELECT CURRENT_TIMESTAMP", NO_PARAMS, |r| r.get(0)); + assert!(result.is_ok()); + let result: Result> = + db.query_row("SELECT CURRENT_TIMESTAMP", NO_PARAMS, |r| r.get(0)); + assert!(result.is_ok()); + } } From 2b8eee2b83ec4ad04ca54c8441aa881fcae176eb Mon Sep 17 00:00:00 2001 From: gwenn Date: Thu, 22 Nov 2018 16:50:10 +0100 Subject: [PATCH 2/3] Fix Timespec FromSql implementations (#431) Make sure SQLite built-in CURRENT_TIMESTAMP output is supported. --- src/types/time.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/types/time.rs b/src/types/time.rs index 8a5f171..980d846 100644 --- a/src/types/time.rs +++ b/src/types/time.rs @@ -3,6 +3,7 @@ extern crate time; use types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; use Result; +const CURRENT_TIMESTAMP_FMT: &str = "%Y-%m-%d %H:%M:%S"; const SQLITE_DATETIME_FMT: &str = "%Y-%m-%dT%H:%M:%S.%fZ"; const SQLITE_DATETIME_FMT_LEGACY: &str = "%Y-%m-%d %H:%M:%S:%f %Z"; @@ -21,10 +22,13 @@ impl FromSql for time::Timespec { value .as_str() .and_then(|s| { - time::strptime(s, SQLITE_DATETIME_FMT).or_else(|err| { - time::strptime(s, SQLITE_DATETIME_FMT_LEGACY) - .or_else(|_| Err(FromSqlError::Other(Box::new(err)))) - }) + match s.len() { + 19 => time::strptime(s, CURRENT_TIMESTAMP_FMT), + _ => time::strptime(s, SQLITE_DATETIME_FMT).or_else(|err| { + time::strptime(s, SQLITE_DATETIME_FMT_LEGACY).or_else(|_| Err(err)) + }), + } + .or_else(|err| Err(FromSqlError::Other(Box::new(err)))) }) .map(|tm| tm.to_timespec()) } @@ -33,7 +37,7 @@ impl FromSql for time::Timespec { #[cfg(test)] mod test { use super::time; - use {Connection, NO_PARAMS}; + use {Connection, Result, NO_PARAMS}; fn checked_memory_handle() -> Connection { let db = Connection::open_in_memory().unwrap(); @@ -67,4 +71,12 @@ mod test { assert_eq!(from, ts); } } + + #[test] + fn test_sqlite_functions() { + let db = checked_memory_handle(); + let result: Result = + db.query_row("SELECT CURRENT_TIMESTAMP", NO_PARAMS, |r| r.get(0)); + assert!(result.is_ok()); + } } From 000566811fb0ec2f0423fb18ca6fd40fd2be1ad7 Mon Sep 17 00:00:00 2001 From: gwenn Date: Thu, 22 Nov 2018 16:53:44 +0100 Subject: [PATCH 3/3] Clippy --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 1e32098..99f7f16 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -800,7 +800,7 @@ impl InnerConnection { #[cfg(feature = "hooks")] fn new(db: *mut ffi::sqlite3) -> InnerConnection { InnerConnection { - db: db, + db, interrupt_lock: Arc::new(Mutex::new(db)), free_commit_hook: None, free_rollback_hook: None,