Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #7 from snakamura/options

Allowed to read options from my.cnf.
  • Loading branch information...
commit 5bc9298eecf0bbd7bb232a43622b818612619a1f 2 parents c36d4cb + 8f10ad6
@bos authored
Showing with 14 additions and 1 deletion.
  1. +14 −1 Database/HDBC/MySQL/Connection.hsc
View
15 Database/HDBC/MySQL/Connection.hsc
@@ -44,6 +44,8 @@ data MySQLConnectInfo = MySQLConnectInfo
, mysqlPort :: Int
-- | The absolute path of the server's Unix socket; e.g., @\"\/var\/lib\/mysql.sock\"@
, mysqlUnixSocket :: String
+ -- | The group name in my.cnf from which it reads options; e.g., @\"test\"@
+ , mysqlGroup :: Maybe String
}
{- | Typical connection information, meant to be overridden partially,
@@ -57,7 +59,7 @@ data MySQLConnectInfo = MySQLConnectInfo
-}
defaultMySQLConnectInfo :: MySQLConnectInfo
-defaultMySQLConnectInfo = MySQLConnectInfo "127.0.0.1" "root" "" "test" 3306 ""
+defaultMySQLConnectInfo = MySQLConnectInfo "127.0.0.1" "root" "" "test" 3306 "" Nothing
data Connection = Connection
{ disconnect :: IO ()
@@ -104,6 +106,11 @@ connectMySQL :: MySQLConnectInfo -> IO Connection
connectMySQL info = do
mysql_ <- mysql_init nullPtr
when (mysql_ == nullPtr) (error "mysql_init failed")
+ case mysqlGroup info of
+ Just group -> withCString group $ \group_ -> do
+ _ <- mysql_options mysql_ #{const MYSQL_READ_DEFAULT_GROUP} (castPtr group_)
+ return ()
+ Nothing -> return ()
withCString (mysqlHost info) $ \host_ ->
withCString (mysqlUser info) $ \user_ ->
withCString (mysqlPassword info) $ \passwd_ ->
@@ -800,6 +807,12 @@ foreign import ccall unsafe mysql_init
:: Ptr MYSQL
-> IO (Ptr MYSQL)
+foreign import ccall unsafe mysql_options
+ :: Ptr MYSQL
+ -> CInt
+ -> Ptr ()
+ -> IO CInt
+
foreign import ccall unsafe mysql_real_connect
:: Ptr MYSQL -- the context
-> CString -- hostname
Please sign in to comment.
Something went wrong with that request. Please try again.