@@ -74,8 +74,10 @@ import Data.Foldable
7474import Data.Function ((&))
7575import Data.Kind
7676import Data.Monoid
77+import Data.Text (unpack)
7778import Data.Traversable
7879import Generics.SOP
80+import PostgreSQL.Binary.Encoding (encodingBytes)
7981
8082import qualified Database.PostgreSQL.LibPQ as LibPQ
8183
@@ -393,7 +395,8 @@ instance (MonadBase IO io, schema0 ~ schema, schema1 ~ schema)
393395 (UnsafeManipulation q :: Manipulation schema ps ys) (params :: x) =
394396 PQ $ \ (K conn) -> do
395397 let
396− toParam' bytes = (LibPQ.invalidOid,bytes,LibPQ.Binary)
398+ toParam' encoding =
399+ (LibPQ.invalidOid, encodingBytes encoding, LibPQ.Binary)
397400 params' = fmap (fmap toParam') (hcollapse (toParams @x @ps params))
398401 q' = q <> ";"
399402 resultMaybe <- liftBase $ LibPQ.execParams conn q' params' LibPQ.Binary
@@ -416,7 +419,7 @@ instance (MonadBase IO io, schema0 ~ schema, schema1 ~ schema)
416419 "traversePrepared: LibPQ.prepare status " <> show status
417420 results <- for list $ \ params -> do
418421 let
419− toParam' bytes = (bytes,LibPQ.Binary)
422+ toParam' encoding = (encodingBytes encoding,LibPQ.Binary)
420423 params' = fmap (fmap toParam') (hcollapse (toParams @x @xs params))
421424 resultMaybe <- LibPQ.execPrepared conn temp params' LibPQ.Binary
422425 case resultMaybe of
@@ -447,7 +450,7 @@ instance (MonadBase IO io, schema0 ~ schema, schema1 ~ schema)
447450 "traversePrepared: LibPQ.prepare status " <> show status
448451 for_ list $ \ params -> do
449452 let
450− toParam' bytes = (bytes,LibPQ.Binary)
453+ toParam' encoding = (encodingBytes encoding, LibPQ.Binary)
451454 params' = fmap (fmap toParam') (hcollapse (toParams @x @xs params))
452455 resultMaybe <- LibPQ.execPrepared conn temp params' LibPQ.Binary
453456 case resultMaybe of
@@ -541,7 +544,9 @@ getRow r (K result :: K LibPQ.Result columns) = liftBase $ do
541544 row' <- traverse (LibPQ.getvalue result r) [0 .. len - 1]
542545 case fromList row' of
543546 Nothing -> error "getRow: found unexpected length"
544− Just row -> return $ fromRow @columns row
547+ Just row -> case fromRow @columns row of
548+ Left parseError -> error $ "fromRow: " <> unpack parseError
549+ Right y -> return y
545550
546551-- | Intended to be used for unfolding in streaming libraries, `nextRow`
547552-- takes a total number of rows (which can be found with `ntuples`)
@@ -559,7 +564,9 @@ nextRow total (K result :: K LibPQ.Result columns) r
559564 row' <- traverse (LibPQ.getvalue result r) [0 .. len - 1]
560565 case fromList row' of
561566 Nothing -> error "nextRow: found unexpected length"
562− Just row -> return $ Just (r+1, fromRow @columns row)
567+ Just row -> case fromRow @columns row of
568+ Left parseError -> error $ "nextRow: " <> unpack parseError
569+ Right y -> return $ Just (r+1, y)
563570
564571-- | Get all rows from a `LibPQ.Result`.
565572getRows
@@ -573,7 +580,9 @@ getRows (K result :: K LibPQ.Result columns) = liftBase $ do
573580 row' <- traverse (LibPQ.getvalue result r) [0 .. len - 1]
574581 case fromList row' of
575582 Nothing -> error "getRows: found unexpected length"
576− Just row -> return $ fromRow @columns row
583+ Just row -> case fromRow @columns row of
584+ Left parseError -> error $ "getRows: " <> unpack parseError
585+ Right y -> return y
577586
578587-- | Get the first row if possible from a `LibPQ.Result`.
579588firstRow
@@ -587,7 +596,9 @@ firstRow (K result :: K LibPQ.Result columns) = liftBase $ do
587596 row' <- traverse (LibPQ.getvalue result 0) [0 .. len - 1]
588597 case fromList row' of
589598 Nothing -> error "firstRow: found unexpected length"
590− Just row -> return . Just $ fromRow @columns row
599+ Just row -> case fromRow @columns row of
600+ Left parseError -> error $ "firstRow: " <> unpack parseError
601+ Right y -> return $ Just y
591602
592603-- | Lifts actions on results from @LibPQ@.
593604liftResult