|
From: Deian S. <de...@cs...> - 2011-03-03 09:49:04
|
Hi all,
I'm trying to use HaskellDB with the HaskellDB-HDBC-SQLite3 driver.
Apparently there is an issue when using CalendarTime. Specifically, I
get:
Convertible: error converting source data SqlString
"2011-02-28T15:57:40 PST" of type SqlValue to type
Data.Time.LocalTime.LocalTime.ZonedTime: Cannot parse using default
format string "%Y-%m-%d %T%Q %z"
when reading from the database.
I read some old posts on the same "bug", but to my knowledge they
didn't really resolve this. I did get things working by patching
HDBC.SqlValue (v 2.2.6.1) and HaskellDB.Sql.Defaults (see below), but
this is not very clean and would like to hear if anyone has a cleaner
solution.
Thanks in advance!
-Deian
======================================
diff -rN old-haskelldb/src/Database/HaskellDB/Sql/Default.hs
new-haskelldb/src/Database/HaskellDB/Sql/Default.hs
514c514,515
< where fmt = iso8601DateFormat (Just "%H:%M:%S")
---
> -- where fmt = iso8601DateFormat (Just "%H:%M:%S")
> where fmt = iso8601DateFormat (Just "%T %Z")
======================================
---
Database/HDBC/SqlValue.hs | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/Database/HDBC/SqlValue.hs b/Database/HDBC/SqlValue.hs
index 9710d55..6e45de2 100644
--- a/Database/HDBC/SqlValue.hs
+++ b/Database/HDBC/SqlValue.hs
@@ -18,6 +18,7 @@ import qualified System.Time as ST
import Data.Time
import Data.Time.Clock.POSIX
import Database.HDBC.Locale (defaultTimeLocale, iso8601DateFormat)
+import qualified System.Locale as SL
import Data.Ratio
import Data.Convertible
import Data.Fixed
@@ -720,7 +721,7 @@ instance Convertible SqlValue LocalTime where
instance Convertible ZonedTime SqlValue where
safeConvert = return . SqlZonedTime
instance Convertible SqlValue ZonedTime where
- safeConvert (SqlString x) = parseTime' (iso8601DateFormat (Just
"%T%Q %z")) x
+ safeConvert (SqlString x) = parseTime' (SL.iso8601DateFormat
(Just "%T %Z")) x
safeConvert (SqlByteString x) = safeConvert (SqlString (BUTF8.toString x))
safeConvert (SqlInt32 x) = safeConvert (SqlInteger (fromIntegral x))
safeConvert (SqlInt64 x) = safeConvert (SqlInteger (fromIntegral x))
--
1.7.1
|