HDBC-postgresql 2.3.2.1 → 2.3.2.2
raw patch · 4 files changed
+46/−23 lines, 4 filesdep ~timesetup-changed
Dependency ranges changed: time
Files
- Database/HDBC/PostgreSQL/Utils.hsc +2/−1
- HDBC-postgresql.cabal +1/−1
- Setup.hs +15/−1
- testsrc/TestTime.hs +28/−20
Database/HDBC/PostgreSQL/Utils.hsc view
@@ -83,7 +83,8 @@ else free x cleanUpBSNulls :: B.ByteString -> B.ByteString-cleanUpBSNulls = B.concatMap convfunc+cleanUpBSNulls bs | 0 `B.notElem` bs = bs+ | otherwise = B.concatMap convfunc bs where convfunc 0 = bsForNull convfunc x = B.singleton x bsForNull = BCHAR8.pack "\\000"
HDBC-postgresql.cabal view
@@ -1,5 +1,5 @@ Name: HDBC-postgresql-Version: 2.3.2.1+Version: 2.3.2.2 License: BSD3 Maintainer: Nicolas Wu <nicolas.wu@gmail.com> Author: John Goerzen
Setup.hs view
@@ -1,4 +1,5 @@ #!/usr/bin/env runhaskell+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-} import Distribution.Simple import Distribution.PackageDescription@@ -26,8 +27,21 @@ } } +-- 'ConstOrId' is a @Cabal-1.16@ vs @Cabal-1.18@ compatibility hack,+-- 'programFindLocation' has a new (unused in this case)+-- parameter. 'ConstOrId' adds this parameter when types say it is+-- mandatory.+class ConstOrId a b where+ constOrId :: a -> b++instance ConstOrId a a where+ constOrId = id++instance ConstOrId a (b -> a) where+ constOrId = const+ pgconfigProgram = (simpleProgram "pgconfig or pg_config") {- programFindLocation = \verbosity -> do+ programFindLocation = \verbosity -> constOrId $ do pgconfig <- findProgramLocation verbosity "pgconfig" pg_config <- findProgramLocation verbosity "pg_config" return (pgconfig `mplus` pg_config)
testsrc/TestTime.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE FlexibleContexts #-}+ module TestTime(tests) where import Test.HUnit import Database.HDBC@@ -14,8 +16,7 @@ import qualified System.Time as ST instance Eq ZonedTime where- a == b = zonedTimeToUTC a == zonedTimeToUTC b &&- zonedTimeZone a == zonedTimeZone b+ a == b = zonedTimeToUTC a == zonedTimeToUTC b testZonedTime :: ZonedTime testZonedTime = fromJust $ parseTime defaultTimeLocale (iso8601DateFormat (Just "%T %z"))@@ -28,7 +29,12 @@ rowdata t = [[SqlInt32 100, toSql t, SqlNull]] -testDTType inputdata convToSqlValue = dbTestCase $ \dbh ->+testDTType :: (Convertible SqlValue a, Show b, Eq b) =>+ a+ -> (a -> SqlValue)+ -> (a -> b)+ -> Test+testDTType inputdata convToSqlValue toComparable = dbTestCase $ \dbh -> do run dbh ("CREATE TABLE hdbctesttime (testid INTEGER PRIMARY KEY NOT NULL, \ \testvalue " ++ dateTimeTypeOfSqlValue value ++ ")") [] finally (testIt dbh) (do commit dbh@@ -43,30 +49,32 @@ case r of [[testidsv, testvaluesv]] -> do assertEqual "testid" (5::Int) (fromSql testidsv)- assertEqual "testvalue" inputdata (fromSql testvaluesv)+ assertEqual "testvalue"+ (toComparable inputdata)+ (toComparable$ fromSql testvaluesv) value = convToSqlValue inputdata -mkTest label inputdata convfunc =- TestLabel label (testDTType inputdata convfunc)+mkTest label inputdata convfunc toComparable =+ TestLabel label (testDTType inputdata convfunc toComparable) tests = TestList $ ((TestLabel "Non-frac" $ testIt testZonedTime) : if supportsFracTime then [TestLabel "Frac" $ testIt testZonedTimeFrac] else []) -testIt baseZonedTime = - TestList [mkTest "Day" baseDay toSql,- mkTest "TimeOfDay" baseTimeOfDay toSql,- mkTest "ZonedTimeOfDay" baseZonedTimeOfDay toSql,- mkTest "LocalTime" baseLocalTime toSql,- mkTest "ZonedTime" baseZonedTime toSql,- mkTest "UTCTime" baseUTCTime toSql,- mkTest "DiffTime" baseDiffTime toSql,- mkTest "POSIXTime" basePOSIXTime posixToSql,- mkTest "ClockTime" baseClockTime toSql,- mkTest "CalendarTime" baseCalendarTime toSql,- mkTest "TimeDiff" baseTimeDiff toSql- ]- where +testIt baseZonedTime =+ TestList [ mkTest "Day" baseDay toSql id+ , mkTest "TimeOfDay" baseTimeOfDay toSql id+ , mkTest "ZonedTimeOfDay" baseZonedTimeOfDay toSql id+ , mkTest "LocalTime" baseLocalTime toSql id+ , mkTest "ZonedTime" baseZonedTime toSql id+ , mkTest "UTCTime" baseUTCTime toSql id+ , mkTest "DiffTime" baseDiffTime toSql id+ , mkTest "POSIXTime" basePOSIXTime posixToSql id+ , mkTest "ClockTime" baseClockTime toSql id+ , mkTest "CalendarTime" baseCalendarTime toSql ST.toClockTime+ , mkTest "TimeDiff" baseTimeDiff toSql id+ ]+ where baseDay :: Day baseDay = localDay baseLocalTime