git.iko.soy/typeable/postgresql-simple
on master help sign in
Move escape functions to internal module
1773773Aleksey Uimanov
src/Database/PostgreSQL/Simple.hs−22
@@ -108,9 +108,6 @@ module Database.PostgreSQL.Simple
108 -- * Helper functions
108 -- * Helper functions
109 , formatMany
109 , formatMany
110 , formatQuery
110 , formatQuery
111− , escapeStringConn
112− , escapeIdentifier
113− , escapeByteaConn
114 ) where
111 ) where
115
112
116import Blaze.ByteString.Builder
113import Blaze.ByteString.Builder
@@ -289,26 +286,7 @@ parseTemplate template =
289
286
290 skipSpace = B.dropWhile isSpace_ascii
287 skipSpace = B.dropWhile isSpace_ascii
291
288
292−escapeStringConn :: Connection -> ByteString -> IO (Either ByteString ByteString)
293−escapeStringConn = escapeWrap PQ.escapeStringConn
294
289
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
312
290
313buildQuery :: Connection -> Query -> ByteString -> [Action] -> IO Builder
291buildQuery :: Connection -> Query -> ByteString -> [Action] -> IO Builder
314buildQuery conn q template xs = zipParams (split template) <$> mapM sub xs
292buildQuery 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
501throwLibPQError conn default_desc = do
501throwLibPQError conn default_desc = do
502 msg <- maybe default_desc id <$> PQ.errorMessage conn
502 msg <- maybe default_desc id <$> PQ.errorMessage conn
503 throwIO $! libPQError msg
503 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