Commits

Bryan O'Sullivan  committed 50015c1

Add insertID.

  • Participants
  • Parent commits 62c5703

Comments (0)

Files changed (2)

File Database/MySQL/Base.hs

     , serverStatus
     -- * Querying
     , query
+    , insertID
     -- ** Escaping
     , escape
     -- ** Results
 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)
   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

File Database/MySQL/Base/C.hsc

     , mysql_stat
     -- * Querying
     , mysql_real_query
+    , mysql_insert_id
     -- ** Escaping
     , mysql_real_escape_string
     -- ** Results
 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