Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code gardening #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Database/MySQL/Internal/Blaze.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE BangPatterns, CPP, MagicHash, OverloadedStrings, UnboxedTuples #-}

-- | This module is designed to provide a shim for @blaze-textual@.
Expand Down
7 changes: 3 additions & 4 deletions Database/MySQL/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ formatMany conn q@(Query template) qs = do
buildQuery :: Connection -> Query -> ByteString -> [Action] -> IO Builder
buildQuery conn q template xs = zipParams queryFragments <$> mapM sub xs
where sub (Plain b) = pure b
sub (Escape s) = (inQuotes . fromByteString) <$> Base.escape conn s
sub (Escape s) = inQuotes . fromByteString <$> Base.escape conn s
sub (Many ys) = mconcat <$> mapM sub ys
zipParams (t:ts) (p:ps) = t `mappend` p `mappend` zipParams ts ps
zipParams [t] [] = t
Expand All @@ -198,8 +198,7 @@ buildQuery conn q template xs = zipParams queryFragments <$> mapM sub xs
-- break a fragment if the question mark is in a string literal.
splitQuery :: ByteString -> [Builder]
splitQuery s =
reverse $ fmap (fromByteString . BS.pack . reverse) $
begin [] (BS.unpack s)
reverse $ fromByteString . BS.pack . reverse <$> begin [] (BS.unpack s)
where
begin = normal []

Expand Down Expand Up @@ -369,7 +368,7 @@ finishFold conn q z0 f = withResult (Base.useResult conn) q $ \r fs ->
[] -> return z
_ -> (f z $! convertResults fs row) >>= loop

withResult :: (IO Base.Result) -> Query -> (Base.Result -> [Field] -> IO a) -> IO a
withResult :: IO Base.Result -> Query -> (Base.Result -> [Field] -> IO a) -> IO a
withResult fetchResult q act = bracket fetchResult Base.freeResult $ \r -> do
ncols <- Base.fieldCount (Right r)
if ncols == 0
Expand Down
2 changes: 1 addition & 1 deletion Database/MySQL/Simple/Param.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE CPP, DeriveDataTypeable, DeriveFunctor, FlexibleInstances,
{-# LANGUAGE CPP, DeriveDataTypeable, FlexibleInstances,
OverloadedStrings, DefaultSignatures #-}

-- |
Expand Down
4 changes: 2 additions & 2 deletions Database/MySQL/Simple/Result.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ instance Result (Ratio Integer) where
Long,LongLong]

instance Result SB.ByteString where
convert f = doConvert f okText $ id
convert f = doConvert f okText id

instance Result LB.ByteString where
convert f = LB.fromChunks . (:[]) . convert f

instance Result ST.Text where
convert f | isText f = doConvert f okText $ ST.decodeUtf8
convert f | isText f = doConvert f okText ST.decodeUtf8
| otherwise = incompatible f (typeOf ST.empty)
"attempt to mix binary and text"

Expand Down
3 changes: 1 addition & 2 deletions mysql-simple.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 0.4.9
homepage: https://github.com/paul-rouse/mysql-simple
bug-reports: https://github.com/paul-rouse/mysql-simple/issues
synopsis: A mid-level MySQL client library.
description:
description:
A mid-level client library for the MySQL database, intended to be
fast and easy to use.
.
Expand Down Expand Up @@ -52,7 +52,6 @@ library
containers,
mysql >= 0.1.7,
pcre-light,
old-locale,
text >= 0.11.0.2,
time >= 1.5
if !impl(ghc >= 8.0)
Expand Down
2 changes: 1 addition & 1 deletion test/CustomTypeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ customTypeSpec conn =
describe "writing a custom type" $ do
it "should work with parameter substitution" $ do
_ <- execute conn "insert into custom (i,c) values (?,?)"
((3::Int), Latin "nuntium")
(3::Int, Latin "nuntium")
result <- query_ conn "select c from custom where i = 3"
result `shouldBe` [Only (Latin "nuntium")]
2 changes: 1 addition & 1 deletion test/DateTimeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Common ()
-- An arbitrary date and time: 2022-05-25 13:09:34.375 UTC
testTime :: UTCTime
testTime = UTCTime (ModifiedJulianDay 59724)
(realToFrac $ (378995 % 8 :: Rational))
(realToFrac (378995 % 8 :: Rational))

testYear :: Day
testYear =
Expand Down
5 changes: 5 additions & 0 deletions test/main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ isCI = do
_ -> False

-- This is how to connect to our test database
--
-- @
-- CREATE USER test@localhost IDENTIFIED BY 'test';
-- GRANT ALL PRIVILEGES ON test.* TO test@localhost;
-- @
testConn :: Bool -> ConnectInfo
testConn ci = defaultConnectInfo {
connectHost = "127.0.0.1"
Expand Down