[Haskell-cafe] HDBC-ODBC and SqlValues

John Goerzen jgoerzen at complete.org
Thu Apr 8 21:15:36 EDT 2010


Tim Docker wrote:
> *Main> fmap (fromSql.head.head) $ quickQuery c "select getdate()" [] ::
> IO Data.Time.Clock.UTCTime
> 2010-04-09 09:59:20.67 UTC
> *Main> fmap (fromSql.head.head) $ quickQuery c "select getdate()" [] ::
> IO Data.Time.LocalTime
> 2010-04-09 09:59:26.313
> *Main> fmap (fromSql.head.head) $ quickQuery c "select getdate()" [] ::
> IO System.Time.CalendarTime
> *** Exception: Convertible: error converting source data SqlString
> "2010-04-09 09:59:37.460" of type SqlValue to type

That is to be expected.  You are converting data from the underlying 
database that does not contain timezone information.  Thus it is not 
possible to populate ctTZ in CalendarTime.

> Data.Time.LocalTime.LocalTime.ZonedTime: Cannot parse using default
> format string "%Y-%m-%d %T%Q %z"
> *Main> fmap (fromSql.head.head) $ quickQuery c "select getdate()" [] ::
> IO System.Time.ClockTime
> *** Exception: Convertible: error converting source data SqlString
> "2010-04-09 09:59:49.940" of type SqlValue to type Integer: Cannot read
> source value as dest type

And here you don't have something in seconds-since-epoch format.  What 
you have is an unzoned date and time.  Therefore it makes sense that you 
can convert it to a LocalTime.  It does not have enough information to 
make it into a CalendarTime because it lacks a zone.  It also isn't in 
seconds-since-epoch format, which is what a ClockTime is.

The conversions to UTCTime and LocalTime work because they do not 
require a timezone to be present in the input data.

-- John


More information about the Haskell-Cafe mailing list