@@ -111,6 +111,7 @@ module Database.PostgreSQL.Simple
111import Blaze.ByteString.Builder
111import Blaze.ByteString.Builder
112 ( Builder, fromByteString, toByteString )
112 ( Builder, fromByteString, toByteString )
113import Blaze.ByteString.Builder.Char8 (fromChar)
113import Blaze.ByteString.Builder.Char8 (fromChar)
114+import Blaze.Text ( integral )
114import Control.Applicative ((<$>), pure)
115import Control.Applicative ((<$>), pure)
115import Control.Exception as E
116import Control.Exception as E
116import Control.Monad (foldM)
117import Control.Monad (foldM)
@@ -482,10 +483,15 @@ doFold FoldOptions{..} conn _template q a0 f = do
483 declare = do
484 declare = do
484 name <- newTempName conn
485 name <- newTempName conn
486+ _ <- execute_ conn $ mconcat
485− _ <- execute_ conn $ "DECLARE " <> name <> " NO SCROLL CURSOR FOR " <> q
487+ [ "DECLARE ", name, " NO SCROLL CURSOR FOR ", q ]
486 return name
488 return name
487− fetch name = query_ conn $
489+ fetch (Query name) = query_ conn $
488− "FETCH FORWARD " <> (Query . B.pack . show) chunkSize <> " FROM " <> name
490+ Query (toByteString (fromByteString "FETCH FORWARD "
491+ <> integral chunkSize
492+ <> fromByteString " FROM "
493+ <> fromByteString name
489 close name =
495 close name =
490 (execute_ conn ("CLOSE " <> name) >> return ()) `E.catch` \ex ->
496 (execute_ conn ("CLOSE " <> name) >> return ()) `E.catch` \ex ->
491 -- Don't throw exception if CLOSE failed because the transaction is
497 -- Don't throw exception if CLOSE failed because the transaction is