Permalink
Browse files

SqlTimestampT converted previously to CalendarTime and now to LocalTi…

…me because of lack of timezone
  • Loading branch information...
1 parent 16f61f8 commit fc9197817cec8485faf4a7842533e3580495f8de Andras Gyomrey committed Oct 4, 2012
@@ -124,7 +124,7 @@ colDescToFieldDesc c = (t, nullable)
SqlLongVarBinaryT -> string
SqlDateT -> CalendarTimeT
SqlTimeT -> CalendarTimeT
- SqlTimestampT -> CalendarTimeT
+ SqlTimestampT -> LocalTimeT
SqlUTCDateTimeT -> CalendarTimeT
SqlUTCTimeT -> CalendarTimeT
SqlTimeWithZoneT -> CalendarTimeT
@@ -198,6 +198,7 @@ hdbcGetInstances =
, getDouble = hdbcGetValue
, getBool = hdbcGetValue
, getCalendarTime = hdbcGetValue
+ , getLocalTime = hdbcGetValue
}
-- hdbcGetValue :: Data.Convertible.Base.Convertible SqlValue a
View
@@ -20,7 +20,8 @@ Library
old-time >= 1 && < 2,
old-locale >= 1 && < 2,
directory >= 1 && < 2,
- containers >= 0.3 && < 1
+ containers >= 0.3 && < 1,
+ time
Extensions:
EmptyDataDecls,
DeriveDataTypeable,
@@ -17,7 +17,7 @@
module Database.HaskellDB.DBLayout
(module Database.HaskellDB.BoundedString
, module Database.HaskellDB.DBSpec
- , CalendarTime
+ , CalendarTime, LocalTime
, Expr, Table, Attr, baseTable
, RecCons, RecNil, FieldTag, fieldName
, hdbMakeEntry, mkAttr, ( # )
@@ -30,6 +30,7 @@ import Database.HaskellDB.HDBRec(Record, RecCons, RecNil, FieldTag
import Database.HaskellDB.BoundedString
import System.Time (CalendarTime)
+import Data.Time.LocalTime (LocalTime)
import Database.HaskellDB.Query (Expr, Table, Attr(..)
, baseTable, attribute, (<<), emptyTable)
import Database.HaskellDB.DBSpec
@@ -42,6 +42,7 @@ import Database.HaskellDB.BoundedList
import Database.HaskellDB.HDBRec
import System.Time
+import Data.Time.LocalTime
import Control.Monad
infix 9 !.
@@ -103,6 +104,8 @@ data GetInstances s =
, getBool :: s -> String -> IO (Maybe Bool)
-- | Get a 'CalendarTime' value.
, getCalendarTime :: s -> String -> IO (Maybe CalendarTime)
+ -- | Get a 'LocalTime' value.
+ , getLocalTime :: s -> String -> IO (Maybe LocalTime)
}
@@ -144,6 +147,7 @@ instance GetValue Integer where getValue = getNonNull
instance GetValue Double where getValue = getNonNull
instance GetValue Bool where getValue = getNonNull
instance GetValue CalendarTime where getValue = getNonNull
+instance GetValue LocalTime where getValue = getNonNull
instance Size n => GetValue (BoundedString n) where getValue = getNonNull
instance GetValue (Maybe String) where getValue = getString
@@ -152,6 +156,7 @@ instance GetValue (Maybe Integer) where getValue = getInteger
instance GetValue (Maybe Double) where getValue = getDouble
instance GetValue (Maybe Bool) where getValue = getBool
instance GetValue (Maybe CalendarTime) where getValue = getCalendarTime
+instance GetValue (Maybe LocalTime) where getValue = getLocalTime
instance Size n => GetValue (Maybe (BoundedString n)) where
getValue fs s f = liftM (liftM trunc) (getValue fs s f)
@@ -21,6 +21,7 @@ module Database.HaskellDB.FieldType
import Data.Dynamic
import System.Time
+import Data.Time.LocalTime
import Database.HaskellDB.HDBRec (RecCons(..), Record, RecNil(..), ShowLabels)
import Database.HaskellDB.BoundedString
@@ -38,6 +39,7 @@ data FieldType =
| DoubleT
| BoolT
| CalendarTimeT
+ | LocalTimeT
| BStrT Int
deriving (Eq,Ord,Show,Read)
@@ -64,6 +66,7 @@ toHaskellType IntegerT = "Integer"
toHaskellType DoubleT = "Double"
toHaskellType BoolT = "Bool"
toHaskellType CalendarTimeT = "CalendarTime"
+toHaskellType LocalTimeT = "LocalTime"
toHaskellType (BStrT a) = "BStr" ++ show a
-- | Given a query, returns a list of the field names and their
@@ -116,6 +119,9 @@ instance ExprType Double where
instance ExprType CalendarTime where
fromHaskellType _ = (CalendarTimeT, False)
+instance ExprType LocalTime where
+ fromHaskellType _ = (LocalTimeT, False)
+
instance (Size n) => ExprType (BoundedString n) where
fromHaskellType b = (BStrT (listBound b), False)
@@ -98,6 +98,7 @@ defaultSqlType _ t =
DoubleT -> SqlType "double precision"
BoolT -> SqlType "bit"
CalendarTimeT -> SqlType "timestamp with time zone"
+ LocalTimeT -> SqlType "timestamp without time zone"
BStrT a -> SqlType1 "varchar" a
-----------------------------------------------------------

0 comments on commit fc91978

Please sign in to comment.