Commits

Bryan O'Sullivan  committed ff40502 Merge

Merge pull request #7 from snakamura/options

Allowed to read options from my.cnf.

  • Participants
  • Parent commits 294cc02, 5c6ec4e

Comments (0)

Files changed (1)

File Database/HDBC/MySQL/Connection.hsc

     , 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,
 
 -}
 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 ()
 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_ ->
  :: 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