Commits

Bryan O'Sullivan  committed 4d4381e

Implement a bunch of info API entry points.

  • Participants
  • Parent commits c633444

Comments (0)

Files changed (2)

File Database/MySQL.hs

     , autocommit
     , ping
     , changeUser
+    -- ** Connection information
     , threadId
+    , serverInfo
+    , hostInfo
+    , protocolInfo
+    -- * General information
+    , clientInfo
+    , clientVersion
     ) where
 
 import Control.Applicative
 import Control.Exception
 import Control.Monad
 import Database.MySQL.C
+import System.IO.Unsafe
 import Data.IORef
 import Data.Word
 import Foreign.C.String
 threadId :: Connection -> IO Word
 threadId conn = fromIntegral <$> withConn conn mysql_thread_id
 
+serverInfo :: Connection -> IO String
+serverInfo conn = withConn conn $ \ptr ->
+                  peekCString =<< mysql_get_server_info ptr
+
+hostInfo :: Connection -> IO String
+hostInfo conn = withConn conn $ \ptr ->
+                peekCString =<< mysql_get_host_info ptr
+
+protocolInfo :: Connection -> IO Word
+protocolInfo conn = withConn conn $ \ptr ->
+                    fromIntegral <$> mysql_get_proto_info ptr
+
+clientInfo :: String
+clientInfo = unsafePerformIO $ peekCString mysql_get_client_info
+{-# NOINLINE clientInfo #-}
+
+clientVersion :: Word
+clientVersion = fromIntegral mysql_get_client_version
+{-# NOINLINE clientVersion #-}
+
 autocommit :: Connection -> Bool -> IO ()
 autocommit conn onOff = withConn conn $ \ptr ->
    withRTSSignalsBlocked (mysql_autocommit ptr b) >>= check "autocommit" ptr

File Database/MySQL/C.hsc

     , mysql_real_connect
     , mysql_close
     , mysql_ping
-    , mysql_thread_id
     , mysql_autocommit
     , mysql_change_user
+    -- ** Connection information
+    , mysql_thread_id
+    , mysql_get_server_info
+    , mysql_get_host_info
+    , mysql_get_proto_info
+    -- * General information
+    , mysql_get_client_info
+    , mysql_get_client_version
     -- * Error handling
     , mysql_errno
     , mysql_error
     -> CString                  -- ^ database
     -> IO MyBool
 
+foreign import ccall safe mysql_get_server_info
+    :: Ptr MYSQL -> IO CString
+
+foreign import ccall safe mysql_get_host_info
+    :: Ptr MYSQL -> IO CString
+
+foreign import ccall safe mysql_get_proto_info
+    :: Ptr MYSQL -> IO CUInt
+
+foreign import ccall safe mysql_get_client_info :: CString
+
+foreign import ccall safe mysql_get_client_version :: CULong
+
 foreign import ccall safe mysql_errno
     :: Ptr MYSQL -> IO CInt