Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Database/SQLite/Simple/FromField.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ instance FromField Word where

instance FromField Double where
fromField (Field (SQLFloat flt) _) = Ok flt
fromField (Field SQLNull _) = Ok (0/0)
fromField f = returnError ConversionFailed f "expecting an SQLFloat column type"

instance FromField Float where
fromField (Field (SQLFloat flt) _) = Ok . double2Float $ flt
fromField (Field SQLNull _) = Ok (0/0)
fromField f = returnError ConversionFailed f "expecting an SQLFloat column type"

instance FromField Bool where
Expand Down
5 changes: 5 additions & 0 deletions test/ParamConv.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ testParamConvNull TestEnv{..} = TestCase $ do
execute conn "INSERT INTO nulltype (id, t1) VALUES (?,?)" (two, "foo" :: String)
[mr2] <- query_ conn "SELECT t1 FROM nulltype WHERE id = 2" :: IO [Only (Maybe String)]
assertEqual "nulls" (Just "foo") (fromOnly mr2)
-- Test null conversion for Float/Double
[Only nanD] <- query_ conn "SELECT NULL" :: IO [Only Double]
assertBool "NULL for Double" $ isNaN nanD
[Only nanF] <- query_ conn "SELECT NULL" :: IO [Only Float]
assertBool "NULL for Float" $ isNaN nanF

testParamConvInt :: TestEnv -> Test
testParamConvInt TestEnv{..} = TestCase $ do
Expand Down