Commits

Bryan O'Sullivan  committed a837a30

Implement threadId

  • Participants
  • Parent commits c0a0add

Comments (0)

Files changed (2)

File Database/MySQL.hs

     , Option(..)
     , defaultConnectInfo
     , Connection
-    , MySQLError(errNumber, errMessage)
+    , MySQLError(errFunction, errNumber, errMessage)
     -- * Connection management
     , connect
     , close
     , ping
+    , threadId
     ) where
 
+import Control.Applicative
 import Data.Typeable (Typeable)
 import Control.Exception
 import Control.Monad
 import Database.MySQL.C
 import Data.IORef
-import Data.Word (Word16)
+import Data.Word
 import Foreign.C.String
 import Foreign.C.Types
 import Foreign.ForeignPtr hiding (newForeignPtr)
 ping conn = withConn conn $ \ptr ->
             withRTSSignalsBlocked (mysql_ping ptr) >>= check "ping" ptr
 
+threadId :: Connection -> IO Word
+threadId conn = fromIntegral <$> withConn conn mysql_thread_id
+
 withConn :: Connection -> (Ptr MYSQL -> IO a) -> IO a
 withConn conn = withForeignPtr (connFP conn)
 

File Database/MySQL/C.hsc

     , mysql_real_connect
     , mysql_close
     , mysql_ping
+    , mysql_thread_id
     -- * Error handling
     , mysql_errno
     , mysql_error
 import Control.Concurrent (rtsSupportsBoundThreads, runInBoundThread)
 import Control.Exception (finally)
 import Foreign.C.String (CString)
-import Foreign.C.Types (CInt)
+import Foreign.C.Types
 import Foreign.Marshal.Alloc (alloca)
 import Foreign.Ptr (Ptr, nullPtr)
 import Foreign.Storable (Storable(..))
 foreign import ccall unsafe mysql_ping
     :: Ptr MYSQL -> IO CInt
 
+foreign import ccall unsafe mysql_thread_id
+    :: Ptr MYSQL -> IO CULong
+
 foreign import ccall unsafe mysql_errno
     :: Ptr MYSQL -> IO CInt