packages feed

mysql 0.1.0.0 → 0.1.0.1

raw patch · 3 files changed

+40/−7 lines, 3 files

Files

Database/MySQL/Base.hs view
@@ -27,7 +27,6 @@     , defaultSSLInfo     , Connection     , Result-    , Field     , Type(..)     , Row     , MySQLError(errFunction, errNumber, errMessage)@@ -49,6 +48,7 @@     , serverStatus     -- * Querying     , query+    , insertID     -- ** Escaping     , escape     -- ** Results@@ -84,7 +84,7 @@ 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)@@ -188,12 +188,14 @@  instance Exception MySQLError +-- | Connection to a MySQL database. data Connection = Connection {       connFP :: ForeignPtr MYSQL     , connClose :: IO ()     , connResult :: IORef (Maybe (Weak Result))     } +-- | Result of a database query. data Result = Result {       resFP :: ForeignPtr MYSQL_RES     , resFields :: {-# UNPACK #-} !Int@@ -209,6 +211,18 @@  -- | Default information for setting up a connection. --+-- Defaults are as follows:+--+-- * Server on @localhost@+--+-- * User @root@+--+-- * No password+--+-- * Database @test@+--+-- * Character set @utf8@+-- -- Use as in the following example: -- -- > connect defaultConnectInfo { connectHost = "db.example.com" }@@ -219,7 +233,7 @@                      , connectUser = "root"                      , connectPassword = ""                      , connectDatabase = "test"-                     , connectOptions = []+                     , connectOptions = [CharsetName "utf8"]                      , connectPath = ""                      , connectSSL = Nothing                      }@@ -234,6 +248,7 @@                  , sslCiphers = ""                  } +-- | Connect to a database. connect :: ConnectInfo -> IO Connection connect ConnectInfo{..} = do   closed <- newIORef False@@ -335,6 +350,11 @@ clientVersion = fromIntegral mysql_get_client_version {-# NOINLINE clientVersion #-} +-- | Turn autocommit on or off.+--+-- By default, MySQL runs with autocommit mode enabled. In this mode,+-- as soon as you modify a table, MySQL stores your modification+-- permanently. autocommit :: Connection -> Bool -> IO () autocommit conn onOff = withConn conn $ \ptr ->    withRTSSignalsBlocked (mysql_autocommit ptr b) >>= check "autocommit" conn@@ -350,7 +370,7 @@       check "changeUser" conn  selectDB :: Connection -> String -> IO ()-selectDB conn db = +selectDB conn db =   withCString db $ \cdb ->     withConn conn $ \ptr ->       withRTSSignalsBlocked (mysql_select_db ptr cdb) >>= check "selectDB" conn@@ -360,6 +380,13 @@   unsafeUseAsCStringLen q $ \(p,l) ->   mysql_real_query ptr p (fromIntegral l) >>= check "query" conn +-- | Return the value generated for an @AUTO_INCREMENT@ column by the+-- previous @INSERT@ or @UPDATE@ statement.+--+-- See <http://dev.mysql.com/doc/refman/5.5/en/mysql-insert-id.html>+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@@ -438,12 +465,12 @@ isResultValid :: Result -> IO Bool isResultValid Result{..}  = readIORef resValid isResultValid EmptyResult = return False-            + freeResult_ :: IORef Bool -> Ptr MYSQL_RES -> IO () freeResult_ valid ptr = do   wasValid <- atomicModifyIORef valid $ \prev -> (False, prev)   when wasValid $ mysql_free_result ptr-    + fetchRow :: Result -> IO [Maybe ByteString] fetchRow res@Result{..}  = withRes "fetchRow" res $ \ptr -> do   rowPtr <- resFetchRow ptr@@ -489,10 +516,12 @@     -1 -> return False     _  -> connectionError "nextResult" conn +-- | Commit the current transaction. commit :: Connection -> IO () commit conn = withConn conn $ \ptr ->               mysql_commit ptr >>= check "commit" conn +-- | Roll back the current transaction. rollback :: Connection -> IO () rollback conn = withConn conn $ \ptr ->                 mysql_rollback ptr >>= check "rollback" conn
Database/MySQL/Base/C.hsc view
@@ -32,6 +32,7 @@     , mysql_stat     -- * Querying     , mysql_real_query+    , mysql_insert_id     -- ** Escaping     , mysql_real_escape_string     -- ** Results@@ -259,6 +260,9 @@  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
mysql.cabal view
@@ -1,5 +1,5 @@ name:           mysql-version:        0.1.0.0+version:        0.1.0.1 homepage:       https://github.com/mailrank/mysql bug-reports:    https://github.com/mailrank/mysql/issues synopsis:       A low-level MySQL client library.