-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Description
The type of executeMany function is the following:
executeMany :: QueryParam p => MySQLConn -> Query -> [[p]] -> IO [OK]But when I'm trying to pass an empty list as an argument of type [[p]] I see the following error:
ERRException (ERR {errCode = 1065, errState = "42000", errMsg = "Query was empty"})I see two possible solutions to this problem:
- Patch implementation of
executeManyfunction to do nothing when empty list is given. - Change type of argument from
[[p]]toNonEmpty [p].
Here is the complete code where I observe the error:
#! /usr/bin/env cabal
{- cabal:
build-depends: base >= 4.11 && < 4.12
, mysql-haskell ^>= 0.8.4.1
, io-streams
-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.String (fromString)
import Database.MySQL.Base
import Database.MySQL.Connection (utf8mb4_unicode_ci)
import qualified System.IO.Streams as Stream
createSchema :: Query
createSchema = fromString $ unlines
[ "DROP TABLE IF EXISTS users;"
, "CREATE TABLE users"
, " ( id INT AUTO_INCREMENT PRIMARY KEY"
, " , name TEXT NOT NULL"
, " ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;"
]
insertUser :: Query
insertUser = "INSERT INTO users (name) VALUES (?)"
main :: IO ()
main = do
(greet, conn) <- connectDetail ConnectInfo
{ ciHost = "127.0.0.1"
, ciPort = 3306
, ciUser = "root"
, ciPassword = "password"
, ciDatabase = "test_db"
, ciCharset = utf8mb4_unicode_ci
}
print greet
print =<< mapM (executeMany_ conn) [createSchema]
print =<< executeMany conn insertUser ([] :: [[MySQLValue]])
(_defs, is) <- query_ conn "SELECT * FROM `users`"
print =<< Stream.toList isMetadata
Metadata
Assignees
Labels
No labels