22
22
23
23
module Database.Oracle.Simple.Internal where
24
24
25
- import Test.QuickCheck
26
- import Data.Time
27
25
import Control.Exception
28
26
import Control.Monad
29
27
import Control.Monad.State.Strict
@@ -32,6 +30,7 @@ import Data.IORef
32
30
import Data.Kind
33
31
import Data.List as L
34
32
import Data.Text
33
+ import Data.Time
35
34
import Data.Typeable
36
35
import Data.Word
37
36
import Foreign
@@ -44,6 +43,7 @@ import Foreign.Storable.Generic
44
43
import GHC.Generics
45
44
import GHC.TypeLits
46
45
import System.IO.Unsafe
46
+ import Test.QuickCheck
47
47
48
48
newtype DPIStmt = DPIStmt (Ptr DPIStmt )
49
49
deriving (Show , Eq )
@@ -204,9 +204,9 @@ toDPIPurity :: DPIPurity -> CUInt
204
204
toDPIPurity = fromIntegral . fromEnum
205
205
206
206
data DPIModeConnClose
207
- = DPI_MODE_CONN_CLOSE_DEFAULT -- 0x0000
208
- | DPI_MODE_CONN_CLOSE_DROP -- 0x0001
209
- | DPI_MODE_CONN_CLOSE_RETAG -- 0x0002
207
+ = DPI_MODE_CONN_CLOSE_DEFAULT -- 0x0000
208
+ | DPI_MODE_CONN_CLOSE_DROP -- 0x0001
209
+ | DPI_MODE_CONN_CLOSE_RETAG -- 0x0002
210
210
deriving (Show , Eq )
211
211
212
212
toDpiModeConnClose :: DPIModeConnClose -> CUInt
@@ -458,8 +458,12 @@ getServerVersion (Connection fptr) versionInfo = do
458
458
alloca $ \ releaseStringPtr -> do
459
459
alloca $ \ versionInfoPtr -> do
460
460
poke versionInfoPtr versionInfo
461
- status <- dpiContext_getServerVersion
462
- conn releaseStringPtr (fromIntegral (10 :: Int )) versionInfoPtr
461
+ status <-
462
+ dpiContext_getServerVersion
463
+ conn
464
+ releaseStringPtr
465
+ (fromIntegral (10 :: Int ))
466
+ versionInfoPtr
463
467
if status == 0
464
468
then (peekCString <=< peek) releaseStringPtr
465
469
else error $ show status <> " oh no!"
@@ -547,21 +551,22 @@ data DPITimestamp = DPITimestamp
547
551
-- to the year, month, day, hour, minutes and seconds
548
552
dpiTimeStampToUTCDPITimeStamp :: DPITimestamp -> DPITimestamp
549
553
dpiTimeStampToUTCDPITimeStamp dpi@ DPITimestamp {.. } = utcDpi
550
- where
551
- offsetInMinutes , currentMinutes :: Int
552
- offsetInMinutes = negate $ (fromIntegral tzHourOffset * 60 ) + fromIntegral tzMinuteOffset
553
- currentMinutes = (fromIntegral hour * 60 ) + fromIntegral minute
554
- (hours, minutes) = ((currentMinutes + offsetInMinutes) `mod` 1440 ) `quotRem` 60
555
-
556
- gregorianDay = fromGregorian (fromIntegral year) (fromIntegral month) (fromIntegral day)
557
- updatedDay | fromIntegral currentMinutes + fromIntegral offsetInMinutes > 1440
558
- = addDays 1 gregorianDay
559
- | fromIntegral currentMinutes + fromIntegral offsetInMinutes < 0
560
- = addDays (- 1 ) gregorianDay
561
- | otherwise = gregorianDay
562
- (year', month', day') = toGregorian updatedDay
563
- utcDpi
564
- = dpi
554
+ where
555
+ offsetInMinutes , currentMinutes :: Int
556
+ offsetInMinutes = negate $ (fromIntegral tzHourOffset * 60 ) + fromIntegral tzMinuteOffset
557
+ currentMinutes = (fromIntegral hour * 60 ) + fromIntegral minute
558
+ (hours, minutes) = ((currentMinutes + offsetInMinutes) `mod` 1440 ) `quotRem` 60
559
+
560
+ gregorianDay = fromGregorian (fromIntegral year) (fromIntegral month) (fromIntegral day)
561
+ updatedDay
562
+ | fromIntegral currentMinutes + fromIntegral offsetInMinutes > 1440 =
563
+ addDays 1 gregorianDay
564
+ | fromIntegral currentMinutes + fromIntegral offsetInMinutes < 0 =
565
+ addDays (- 1 ) gregorianDay
566
+ | otherwise = gregorianDay
567
+ (year', month', day') = toGregorian updatedDay
568
+ utcDpi =
569
+ dpi
565
570
{ tzHourOffset = 0
566
571
, tzMinuteOffset = 0
567
572
, year = fromIntegral year'
@@ -573,19 +578,19 @@ dpiTimeStampToUTCDPITimeStamp dpi@DPITimestamp{..} = utcDpi
573
578
574
579
instance Arbitrary DPITimestamp where
575
580
arbitrary = do
576
- year <- choose (1000 , 2023 )
577
- month <- choose (1 , 12 )
578
- day <- choose (1 , 28 )
579
- hour <- choose (1 , 23 )
580
- minute <- choose (1 , 59 )
581
- second <- choose (1 , 59 )
582
- fsecond <- choose (0 , 100000 )
583
- tzHourOffset <- choose (- 14 , 14 )
581
+ year <- choose (1000 , 2023 )
582
+ month <- choose (1 , 12 )
583
+ day <- choose (1 , 28 )
584
+ hour <- choose (1 , 23 )
585
+ minute <- choose (1 , 59 )
586
+ second <- choose (1 , 59 )
587
+ fsecond <- choose (0 , 100000 )
588
+ tzHourOffset <- choose (- 14 , 14 )
584
589
tzMinuteOffset <-
585
590
if signum tzHourOffset < 0
586
591
then choose (- 59 , 0 )
587
592
else choose (0 , 59 )
588
- pure DPITimestamp {.. }
593
+ pure DPITimestamp {.. }
589
594
590
595
instance HasDPINativeType DPITimestamp where
591
596
dpiNativeType Proxy = DPI_NATIVE_TYPE_TIMESTAMP
@@ -974,4 +979,9 @@ isHealthy (Connection fptr) =
974
979
withForeignPtr fptr $ \ conn -> do
975
980
alloca $ \ healthPtr -> do
976
981
throwOracleError =<< dpiConn_getIsHealthy conn healthPtr
977
- (== 1 ) <$> peek healthPtr
982
+ (== 1 ) <$> peek healthPtr
983
+
984
+ -- | The 1-tuple type or single-value "collection".
985
+ -- Structurally equivalent to 'Data.Functor.Identity.Identity'.
986
+ newtype Only a = Only { fromOnly :: a }
987
+ deriving stock (Eq , Ord , Read , Show , Generic )
0 commit comments