- data Connection
- disconnect :: Connection -> IO ()
- execute :: Connection -> String -> IO ()
- data Statement
- query :: Connection -> String -> IO Statement
- closeStatement :: Statement -> IO ()
- fetch :: Statement -> IO Bool
- type FieldDef = (String, SqlType, Bool)
- data SqlType
- = SqlChar Int
- | SqlVarChar Int
- | SqlLongVarChar Int
- | SqlText
- | SqlWChar Int
- | SqlWVarChar Int
- | SqlWLongVarChar Int
- | SqlDecimal Int Int
- | SqlNumeric Int Int
- | SqlSmallInt
- | SqlMedInt
- | SqlInteger
- | SqlReal
- | SqlFloat
- | SqlDouble
- | SqlBit
- | SqlTinyInt
- | SqlBigInt
- | SqlBinary Int
- | SqlVarBinary Int
- | SqlLongVarBinary Int
- | SqlDate
- | SqlTime
- | SqlTimeTZ
- | SqlAbsTime
- | SqlRelTime
- | SqlTimeInterval
- | SqlAbsTimeInterval
- | SqlTimeStamp
- | SqlDateTime
- | SqlDateTimeTZ
- | SqlYear
- | SqlSET
- | SqlENUM
- | SqlBLOB
- | SqlMoney
- | SqlINetAddr
- | SqlCIDRAddr
- | SqlMacAddr
- | SqlPoint
- | SqlLSeg
- | SqlPath
- | SqlBox
- | SqlPolygon
- | SqlLine
- | SqlCircle
- | SqlUnknown Int
- class SqlBind a where
- fromSqlCStringLen :: FieldDef -> CString -> Int -> IO a
- fromSqlValue :: SqlType -> String -> Maybe a
- toSqlValue :: a -> String
- getFieldValue :: SqlBind a => Statement -> String -> IO a
- getFieldValueMB :: SqlBind a => Statement -> String -> IO (Maybe a)
- getFieldValue' :: SqlBind a => Statement -> String -> a -> IO a
- getFieldValueType :: Statement -> String -> (SqlType, Bool)
- getFieldsTypes :: Statement -> [(String, SqlType, Bool)]
- inTransaction :: Connection -> (Connection -> IO a) -> IO a
- data SqlError
- = SqlError {
- seState :: String
- seNativeError :: Int
- seErrorMsg :: String
- | SqlNoData
- | SqlInvalidHandle
- | SqlStillExecuting
- | SqlNeedData
- | SqlBadTypeCast { }
- | SqlFetchNull { }
- | SqlUnknownField { }
- | SqlUnsupportedOperation
- | SqlClosedHandle
- = SqlError {
- catchSql :: IO a -> (SqlError -> IO a) -> IO a
- handleSql :: (SqlError -> IO a) -> IO a -> IO a
- sqlExceptions :: Exception -> Maybe SqlError
- forEachRow :: (Statement -> s -> IO s) -> Statement -> s -> IO s
- forEachRow' :: (Statement -> IO ()) -> Statement -> IO ()
- collectRows :: (Statement -> IO a) -> Statement -> IO [a]
- tables :: Connection -> IO [String]
- describe :: Connection -> String -> IO [FieldDef]
- data Point = Point Double Double
- data Line = Line Point Point
- data Path
- = OpenPath [Point]
- | ClosedPath [Point]
- data Box = Box Double Double Double Double
- data Circle = Circle Point Double
- data Polygon = Polygon [Point]
Connect/Disconnect
data Connection Source
A Connection
type represents a connection to a database, through which you can operate on the it.
In order to create the connection you need to use the connect
function from the module for
your prefered backend.
disconnect :: Connection -> IO ()Source
Closes the connection. Performing disconnect
on a connection that has already been
closed has no effect. All other operations on a closed connection will fail.
Command Execution Functions
Once a connection to a database has been successfully established, the functions described here are used to perform SQL queries and commands.
:: Connection | the database connection |
-> String | the text of SQL command |
-> IO () |
Submits a command to the database.
:: Connection | the database connection |
-> String | the text of SQL query |
-> IO Statement | the associated statement. Must be closed with
the |
Executes a query and returns a result set
closeStatement :: Statement -> IO ()Source
closeStatement
stops processing associated with a specific statement, closes any open cursors
associated with the statement, discards pending results, and frees all resources associated with
the statement. Performing closeStatement
on a statement that has already been
closed has no effect. All other operations on a closed statement will fail.
fetch :: Statement -> IO BoolSource
fetch
fetches the next rowset of data from the result set.
The values from columns can be retrieved with getFieldValue
function.
Retrieving Statement values and types
SqlChar Int | |
SqlVarChar Int | |
SqlLongVarChar Int | |
SqlText | |
SqlWChar Int | |
SqlWVarChar Int | |
SqlWLongVarChar Int | |
SqlDecimal Int Int | |
SqlNumeric Int Int | |
SqlSmallInt | |
SqlMedInt | |
SqlInteger | |
SqlReal | |
SqlFloat | |
SqlDouble | |
SqlBit | |
SqlTinyInt | |
SqlBigInt | |
SqlBinary Int | |
SqlVarBinary Int | |
SqlLongVarBinary Int | |
SqlDate | |
SqlTime | |
SqlTimeTZ | |
SqlAbsTime | |
SqlRelTime | |
SqlTimeInterval | |
SqlAbsTimeInterval | |
SqlTimeStamp | |
SqlDateTime | |
SqlDateTimeTZ | |
SqlYear | |
SqlSET | |
SqlENUM | |
SqlBLOB | |
SqlMoney | |
SqlINetAddr | |
SqlCIDRAddr | |
SqlMacAddr | |
SqlPoint | |
SqlLSeg | |
SqlPath | |
SqlBox | |
SqlPolygon | |
SqlLine | |
SqlCircle | |
SqlUnknown Int | HSQL returns |
fromSqlCStringLen :: FieldDef -> CString -> Int -> IO aSource
fromSqlValue :: SqlType -> String -> Maybe aSource
toSqlValue :: a -> StringSource
Retrieves the value of field with the specified name.
Retrieves the value of field with the specified name.
If the field value is null
then the function will return the default value.
getFieldValueType :: Statement -> String -> (SqlType, Bool)Source
Returns the type and the nullable
flag for field with specified name
getFieldsTypes :: Statement -> [(String, SqlType, Bool)]Source
Returns the list of fields with their types and nullable
flags
Transactions
:: Connection | |
-> (Connection -> IO a) | an action |
-> IO a | the returned value is the result returned from action |
The inTransaction
function executes the specified action in transaction mode.
If the action completes successfully then the transaction will be commited.
If the action completes with an exception then the transaction will be rolled back
and the exception will be throw again.
SQL Exceptions handling
Utilities
The forEachRow
function iterates through the result set in Statement
and
executes the given action for each row in the set. The function closes the Statement
after the last row processing or if the given action raises an exception.
forEachRow' :: (Statement -> IO ()) -> Statement -> IO ()Source
The 'forEachRow\'' function is analogous to forEachRow
but doesn't provide state.
The function closes the Statement
after the last row processing or if the given
action raises an exception.
collectRows :: (Statement -> IO a) -> Statement -> IO [a]Source
The collectRows
function iterates through the result set in Statement
and
executes the given action for each row in the set. The values returned from action
are collected and returned as list. The function closes the Statement
after the
last row processing or if the given action raises an exception.
Metadata
:: Connection | Database connection |
-> IO [String] | The names of all tables in the database. |
List all tables in the database.
:: Connection | Database connection |
-> String | Name of a database table |
-> IO [FieldDef] | The list of fields in the table |
List all columns in a table along with their types and nullable
flags