git.iko.soy/typeable/postgresql-simple
on master help sign in
Minor optimizations of fold's query generation
commit125bc725f4aa7bf4a04521853cb1933c57d54ccc authorLeon P Smith <leon@melding-monads.com> dateWed 29 May 2013, 01:42 (13 years ago) parent8c7629f
1 file changed+9−3
src/Database/PostgreSQL/Simple.hs+9−3
src/Database/PostgreSQL/Simple.hs+9−3
@@ -111,6 +111,7 @@ module Database.PostgreSQL.Simple
111111import Blaze.ByteString.Builder
112112 ( Builder, fromByteString, toByteString )
113113import Blaze.ByteString.Builder.Char8 (fromChar)
114+import Blaze.Text ( integral )
114115import Control.Applicative ((<$>), pure)
115116import Control.Exception as E
116117import Control.Monad (foldM)
@@ -482,10 +483,15 @@ doFold FoldOptions{..} conn _template q a0 f = do
482483 where
483484 declare = do
484485 name <- newTempName conn
485− _ <- execute_ conn $ "DECLARE " <> name <> " NO SCROLL CURSOR FOR " <> q
486+ _ <- execute_ conn $ mconcat
487+ [ "DECLARE ", name, " NO SCROLL CURSOR FOR ", q ]
486488 return name
487− fetch name = query_ conn $
488− "FETCH FORWARD " <> (Query . B.pack . show) chunkSize <> " FROM " <> name
489+ fetch (Query name) = query_ conn $
490+ Query (toByteString (fromByteString "FETCH FORWARD "
491+ <> integral chunkSize
492+ <> fromByteString " FROM "
493+ <> fromByteString name
494+ ))
489495 close name =
490496 (execute_ conn ("CLOSE " <> name) >> return ()) `E.catch` \ex ->
491497 -- Don't throw exception if CLOSE failed because the transaction is