postgresql-simple 0.4.4.1 → 0.4.5.0
raw patch · 3 files changed
+39/−6 lines, 3 files
Files
- postgresql-simple.cabal +2/−2
- src/Database/PostgreSQL/Simple/FromField.hs +26/−4
- test/Main.hs +11/−0
postgresql-simple.cabal view
@@ -1,5 +1,5 @@ Name: postgresql-simple-Version: 0.4.4.1+Version: 0.4.5.0 Synopsis: Mid-Level PostgreSQL client library Description: Mid-Level PostgreSQL client library, forked from mysql-simple.@@ -81,7 +81,7 @@ source-repository this type: git location: http://github.com/lpsmith/postgresql-simple- tag: v0.4.4.1+ tag: v0.4.5.0 test-suite test type: exitcode-stdio-1.0
src/Database/PostgreSQL/Simple/FromField.hs view
@@ -34,6 +34,13 @@ If this is unacceptable, you may find 'Database.PostgreSQL.Simple.FromRow.fieldWith' useful. +Also note that while converting to a 'Double' through the 'Scientific' type+is likely somewhat faster than converting through the 'Rational' type,+the 'Scientific' type has no way to represent @NaN@ and @±Infinity@ values.+Thus, if you need precision conversion of regular floating point values+and the possibility of receiving these special values from the backend,+stick with 'Rational'.+ Because 'FromField' is a typeclass, one may provide conversions to additional Haskell types without modifying postgresql-simple. This is particularly useful for supporting PostgreSQL types that postgresql-simple@@ -104,7 +111,7 @@ #include "MachDeps.h" -import Control.Applicative ( (<|>), (<$>), pure )+import Control.Applicative ( (<|>), (<$>), pure, (*>) ) import Control.Concurrent.MVar (MVar, newMVar) import Control.Exception (Exception) import qualified Data.Aeson as JSON@@ -138,6 +145,7 @@ import Data.UUID (UUID) import qualified Data.UUID as UUID import Data.Scientific (Scientific)+import GHC.Real (infinity, notANumber) -- | Exception thrown if conversion from a SQL value to a Haskell -- value fails.@@ -314,18 +322,18 @@ -- | int2, float4 (Uses attoparsec's 'double' routine, for -- better accuracy convert to 'Scientific' or 'Rational' first) instance FromField Float where- fromField = atto ok (realToFrac <$> double)+ fromField = atto ok (realToFrac <$> pg_double) where ok = $(mkCompats [TI.float4,TI.int2]) -- | int2, int4, float4, float8 (Uses attoparsec's 'double' routine, for -- better accuracy convert to 'Scientific' or 'Rational' first) instance FromField Double where- fromField = atto ok double+ fromField = atto ok pg_double where ok = $(mkCompats [TI.float4,TI.float8,TI.int2,TI.int4]) -- | int2, int4, float4, float8, numeric instance FromField (Ratio Integer) where- fromField = atto ok rational+ fromField = atto ok pg_rational where ok = $(mkCompats [TI.float4,TI.float8,TI.int2,TI.int4,TI.numeric]) -- | int2, int4, float4, float8, numeric@@ -335,6 +343,20 @@ unBinary :: Binary t -> t unBinary (Binary x) = x++pg_double :: Parser Double+pg_double+ = (string "NaN" *> pure ( 0 / 0))+ <|> (string "Infinity" *> pure ( 1 / 0))+ <|> (string "-Infinity" *> pure (-1 / 0))+ <|> double++pg_rational :: Parser Rational+pg_rational+ = (string "NaN" *> pure notANumber )+ <|> (string "Infinity" *> pure infinity )+ <|> (string "-Infinity" *> pure (-infinity))+ <|> rational -- | bytea, name, text, \"char\", bpchar, varchar, unknown instance FromField SB.ByteString where
test/Main.hs view
@@ -43,6 +43,7 @@ , TestLabel "Unicode" . testUnicode , TestLabel "Values" . testValues , TestLabel "Copy" . testCopy+ , TestLabel "Double" . testDouble ] testBytea :: TestEnv -> Test@@ -305,6 +306,16 @@ case mrow of CopyOutDone _ -> return rows CopyOutRow row -> loop (row:rows)++testDouble :: TestEnv -> Test+testDouble TestEnv{..} = TestCase $ do+ [Only (x :: Double)] <- query_ conn "SELECT 'NaN'::float8"+ assertBool "expected NaN" (isNaN x)+ [Only (x :: Double)] <- query_ conn "SELECT 'Infinity'::float8"+ x @?= (1 / 0)+ [Only (x :: Double)] <- query_ conn "SELECT '-Infinity'::float8"+ x @?= (-1 / 0)+ data TestException = TestException