Commits

Bryan O'Sullivan  committed 1759329

Seek and tell, commit and rollback.

  • Participants
  • Parent commits 13adc8a

Comments (0)

Files changed (3)

File Database/MySQL.hs

     , Result
     , Field
     , Type(..)
+    , Row
     , MySQLError(errFunction, errNumber, errMessage)
     -- * Connection management
     , connect
     , useResult
     , fetchRow
     , fetchFields
+    , dataSeek
+    , rowSeek
+    , rowTell
     -- ** Multiple results
     , nextResult
+    -- * Transactions
+    , commit
+    , rollback
     -- * General information
     , clientInfo
     , clientVersion
   peekArray resFields =<< resFetchFields ptr
 fetchFields EmptyResult{..} = return []
 
+newtype Row = Row MYSQL_ROW_OFFSET
+
+dataSeek :: Result -> Int64 -> IO ()
+dataSeek res row = withRes "dataSeek" res $ \ptr ->
+  mysql_data_seek ptr (fromIntegral row)
+
+rowTell :: Result -> IO Row
+rowTell res = withRes "rowTell" res $ \ptr ->
+  Row <$> mysql_row_tell ptr
+
+rowSeek :: Result -> Row -> IO Row
+rowSeek res (Row row) = withRes "rowSeek" res $ \ptr ->
+  Row <$> mysql_row_seek ptr row
+
 nextResult :: Connection -> IO Bool
 nextResult conn = withConn conn $ \ptr -> do
   i <- withRTSSignalsBlocked $ mysql_next_result ptr
     -1 -> return False
     _  -> connectionError "nextResult" conn
 
+commit :: Connection -> IO ()
+commit conn = withConn conn $ \ptr ->
+              mysql_commit ptr >>= check "commit" conn
+
+rollback :: Connection -> IO ()
+rollback conn = withConn conn $ \ptr ->
+                mysql_rollback ptr >>= check "rollback" conn
+
 escape :: Connection -> ByteString -> IO ByteString
 escape conn bs = withConn conn $ \ptr ->
   unsafeUseAsCStringLen bs $ \(p,l) ->

File Database/MySQL/C.hsc

     , mysql_free_result
     , mysql_fetch_fields
     , mysql_fetch_fields_nonblock
+    , mysql_data_seek
+    , mysql_row_seek
+    , mysql_row_tell
     -- ** Multiple results
     , mysql_next_result
+    -- * Transactions
+    , mysql_commit
+    , mysql_rollback
     -- * General information
     , mysql_get_client_info
     , mysql_get_client_version
 foreign import ccall safe "mysql.h mysql_fetch_fields" mysql_fetch_fields_nonblock
     :: Ptr MYSQL_RES -> IO (Ptr Field)
 
+foreign import ccall safe mysql_data_seek
+    :: Ptr MYSQL_RES -> CULLong -> IO ()
+
+foreign import ccall safe mysql_row_seek
+    :: Ptr MYSQL_RES -> MYSQL_ROW_OFFSET -> IO MYSQL_ROW_OFFSET
+
+foreign import ccall safe mysql_row_tell
+    :: Ptr MYSQL_RES -> IO MYSQL_ROW_OFFSET
+
 foreign import ccall unsafe mysql_next_result
     :: Ptr MYSQL -> IO CInt
 
+foreign import ccall unsafe mysql_commit
+    :: Ptr MYSQL -> IO MyBool
+
+foreign import ccall unsafe mysql_rollback
+    :: Ptr MYSQL -> IO MyBool
+
 foreign import ccall unsafe mysql_fetch_row
     :: Ptr MYSQL_RES -> IO MYSQL_ROW
 

File Database/MySQL/Types.hsc

     , MYSQL
     , MYSQL_RES
     , MYSQL_ROW
+    , MYSQL_ROWS
+    , MYSQL_ROW_OFFSET
     , MyBool
     -- * Field flags
     , hasAllFlags
 
 data MYSQL
 data MYSQL_RES
+data MYSQL_ROWS
 type MYSQL_ROW = Ptr (Ptr CChar)
+type MYSQL_ROW_OFFSET = Ptr MYSQL_ROWS
 type MyBool = CChar
 
 -- | Column types supported by MySQL.