packages feed

relational-query-HDBC 0.6.7.0 → 0.6.7.1

raw patch · 4 files changed

+86/−4 lines, 4 filesdep +QuickCheckdep +quickcheck-simpledep +relational-query-HDBCdep ~HDBCPVP ok

version bump matches the API change (PVP)

Dependencies added: QuickCheck, quickcheck-simple, relational-query-HDBC

Dependency ranges changed: HDBC

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -1,5 +1,10 @@ <!-- -*- Markdown -*- --> +## 0.6.7.1++- fix do safe convert for integral conversion from SQL value.+- add test suite of conversion from and to SQL value.+ ## 0.6.7.0  - add bulkInsert definitions, and deprecate chunksInsert.
relational-query-HDBC.cabal view
@@ -1,5 +1,5 @@ name:                relational-query-HDBC-version:             0.6.7.0+version:             0.6.7.1 synopsis:            HDBC instance of relational-query and typed query interface for HDBC description:         This package contains the HDBC instance of relational-query and                      the typed query interface for HDBC.@@ -72,6 +72,18 @@    default-language:    Haskell2010 +test-suite convertible-iso+  build-depends:         base <5+                       , QuickCheck+                       , quickcheck-simple+                       , convertible+                       , HDBC+                       , relational-query-HDBC+  type:                exitcode-stdio-1.0+  main-is:             convertibleIso.hs+  hs-source-dirs:      test+  ghc-options:         -Wall+  default-language:    Haskell2010  source-repository head   type:       git
src/Database/HDBC/SqlValueExtra.hs view
@@ -1,9 +1,10 @@ {-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleContexts #-} {-# OPTIONS -fno-warn-orphans #-}  -- | -- Module      : Database.HDBC.SqlValueExtra--- Copyright   : 2013 Kei Hibino+-- Copyright   : 2013-2018 Kei Hibino -- License     : BSD3 -- -- Maintainer  : ex8k.hibino@gmail.com@@ -20,9 +21,9 @@ safeConvertFromIntegral32 i =   safeConvert (fromIntegral i :: Int32) -safeConvertToIntegral32 :: Integral a => SqlValue -> ConvertResult a+safeConvertToIntegral32 :: Convertible Int32 a => SqlValue -> ConvertResult a safeConvertToIntegral32 v =-  fmap fromIntegral (safeConvert v :: ConvertResult Int32)+  safeConvert =<< (safeConvert v :: ConvertResult Int32)  instance Convertible Int8 SqlValue where   safeConvert = safeConvertFromIntegral32
+ test/convertibleIso.hs view
@@ -0,0 +1,64 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE FlexibleContexts #-}++import Control.Applicative ((<$>))+import Data.Int (Int8, Int16)+import Data.Convertible (Convertible, safeConvert, ConvertResult)+import Database.HDBC (SqlValue (SqlInteger))++import Test.QuickCheck (Arbitrary (..), resize)+import Test.QuickCheck.Simple (qcTest, defaultMain)++import Database.HDBC.Record.Persistable ()++++prop_toFromQvInt8 :: Int8 -> Bool+prop_toFromQvInt8 i8 = Right i8 == (safeConvert =<< sv)+  where+    sv :: ConvertResult SqlValue+    sv = safeConvert i8++prop_toFromQvInt16 :: Int16 -> Bool+prop_toFromQvInt16 i16 = Right i16 == (safeConvert =<< sv)+  where+    sv :: ConvertResult SqlValue+    sv = safeConvert i16+++newtype IntegerR i =+  IntegerR Integer+  deriving (Eq, Show)++instance Arbitrary (IntegerR Int8) where+  arbitrary = IntegerR <$> resize 1000 arbitrary++instance Arbitrary (IntegerR Int16) where+  arbitrary = IntegerR <$> resize 100000 arbitrary+++prop_fromToQvBounded :: (Integral a, Convertible SqlValue a, Convertible a SqlValue)+                     => a -> a -> IntegerR a -> Bool+prop_fromToQvBounded mn' mx' (IntegerR i)+  | i < mn || mx < i  =  True+  | otherwise         =  Right sv == (safeConvert =<< ix)+  where+    sv = SqlInteger i+    ix = safeConvert sv `asTypeOf` Right mn'+    mn = fromIntegral mn'+    mx = fromIntegral mx'++prop_fromToQvInt8 :: IntegerR Int8 -> Bool+prop_fromToQvInt8 = prop_fromToQvBounded minBound maxBound++prop_fromToQvInt16 :: IntegerR Int16 -> Bool+prop_fromToQvInt16 = prop_fromToQvBounded minBound maxBound++main :: IO ()+main =+  defaultMain+  [ qcTest "int8  - to SqlV from SqlV" prop_toFromQvInt8+  , qcTest "int16 - to SqlV from SqlV" prop_toFromQvInt16+  , qcTest "int8  - from SqlV to SqlV" prop_fromToQvInt8+  , qcTest "int16 - from SqlV to SqlV" prop_fromToQvInt16+  ]