Permalink
Browse files

Add insertID.

  • Loading branch information...
1 parent d661821 commit 9a74826a287dc561b68495c210dd8e3204a89429 @bos bos committed Apr 28, 2011
Showing with 9 additions and 1 deletion.
  1. +5 −1 Database/MySQL/Base.hs
  2. +4 −0 Database/MySQL/Base/C.hsc
View
@@ -49,6 +49,7 @@ module Database.MySQL.Base
, serverStatus
-- * Querying
, query
+ , insertID
-- ** Escaping
, escape
-- ** Results
@@ -84,7 +85,7 @@ import Data.IORef (IORef, atomicModifyIORef, newIORef, readIORef, writeIORef)
import Data.Int (Int64)
import Data.List (foldl')
import Data.Typeable (Typeable)
-import Data.Word (Word, Word16)
+import Data.Word (Word, Word16, Word64)
import Database.MySQL.Base.C
import Database.MySQL.Base.Types
import Foreign.C.String (CString, peekCString, withCString)
@@ -360,6 +361,9 @@ query conn q = withConn conn $ \ptr ->
unsafeUseAsCStringLen q $ \(p,l) ->
mysql_real_query ptr p (fromIntegral l) >>= check "query" conn
+insertID :: Connection -> IO Word64
+insertID conn = fromIntegral <$> (withConn conn $ mysql_insert_id)
+
-- | Return the number of fields (columns) in a result.
--
-- * If 'Left' 'Connection', returns the number of columns for the most
@@ -32,6 +32,7 @@ module Database.MySQL.Base.C
, mysql_stat
-- * Querying
, mysql_real_query
+ , mysql_insert_id
-- ** Escaping
, mysql_real_escape_string
-- ** Results
@@ -260,6 +261,9 @@ foreign import ccall unsafe mysql_stat
foreign import ccall unsafe mysql_real_query
:: Ptr MYSQL -> CString -> CULong -> IO CInt
+foreign import ccall safe mysql_insert_id
+ :: Ptr MYSQL -> IO CULLong
+
foreign import ccall safe mysql_field_count
:: Ptr MYSQL -> IO CUInt

0 comments on commit 9a74826

Please sign in to comment.