git.iko.soy/typeable/postgresql-simple
on master help sign in
Move escape functions to internal module
commit1773773bc2e54457806d4b1422a7864b928b670c authorAleksey Uimanov <s9gf4ult@gmail.com> dateThu 26 Feb 2015, 12:39 (12 years ago) parent9f206a5
2 files changed+21−22
src/Database/PostgreSQL/Simple.hs−22 src/Database/PostgreSQL/Simple/Internal.hs+21
src/Database/PostgreSQL/Simple.hs−22
@@ -108,9 +108,6 @@ module Database.PostgreSQL.Simple
108108 -- * Helper functions
109109 , formatMany
110110 , formatQuery
111− , escapeStringConn
112− , escapeIdentifier
113− , escapeByteaConn
114111 ) where
115112
116113import Blaze.ByteString.Builder
@@ -289,26 +286,7 @@ parseTemplate template =
289286
290287 skipSpace = B.dropWhile isSpace_ascii
291288
292−escapeStringConn :: Connection -> ByteString -> IO (Either ByteString ByteString)
293−escapeStringConn = escapeWrap PQ.escapeStringConn
294289
295−escapeIdentifier :: Connection -> ByteString -> IO (Either ByteString ByteString)
296−escapeIdentifier = escapeWrap PQ.escapeIdentifier
297−
298−escapeByteaConn :: Connection -> ByteString -> IO (Either ByteString ByteString)
299−escapeByteaConn = escapeWrap PQ.escapeByteaConn
300−
301−escapeWrap :: (PQ.Connection -> ByteString -> IO (Maybe ByteString))
302− -> Connection
303− -> ByteString
304− -> IO (Either ByteString ByteString)
305−escapeWrap f conn s =
306− withConnection conn $ \c ->
307− f c s >>= checkError c
308−
309−checkError :: PQ.Connection -> Maybe a -> IO (Either ByteString a)
310−checkError _ (Just x) = return $ Right x
311−checkError c Nothing = Left . maybe "" id <$> PQ.errorMessage c
312290
313291buildQuery :: Connection -> Query -> ByteString -> [Action] -> IO Builder
314292buildQuery conn q template xs = zipParams (split template) <$> mapM sub xs
src/Database/PostgreSQL/Simple/Internal.hs+21
@@ -501,3 +501,24 @@ throwLibPQError :: PQ.Connection -> ByteString -> IO a
501501throwLibPQError conn default_desc = do
502502 msg <- maybe default_desc id <$> PQ.errorMessage conn
503503 throwIO $! libPQError msg
504+
505+checkError :: PQ.Connection -> Maybe a -> IO (Either ByteString a)
506+checkError _ (Just x) = return $ Right x
507+checkError c Nothing = Left . maybe "" id <$> PQ.errorMessage c
508+
509+escapeWrap :: (PQ.Connection -> ByteString -> IO (Maybe ByteString))
510+ -> Connection
511+ -> ByteString
512+ -> IO (Either ByteString ByteString)
513+escapeWrap f conn s =
514+ withConnection conn $ \c ->
515+ f c s >>= checkError c
516+
517+escapeStringConn :: Connection -> ByteString -> IO (Either ByteString ByteString)
518+escapeStringConn = escapeWrap PQ.escapeStringConn
519+
520+escapeIdentifier :: Connection -> ByteString -> IO (Either ByteString ByteString)
521+escapeIdentifier = escapeWrap PQ.escapeIdentifier
522+
523+escapeByteaConn :: Connection -> ByteString -> IO (Either ByteString ByteString)
524+escapeByteaConn = escapeWrap PQ.escapeByteaConn