Database.HSQL
Contents
Description
- 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)
- class SqlBind a where
- fromSqlCStringLen :: FieldDef -> CString -> Int -> IO a
- 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
- forEachRow :: (Statement -> s -> IO s) -> Statement -> s -> IO s
- forEachRow' :: (Statement -> IO ()) -> Statement -> IO ()
- collectRows :: (Statement -> IO a) -> Statement -> 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 x => x -> Maybe SqlError
- 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]
- data INetAddr = INetAddr Int Int Int Int Int
- data MacAddr = MacAddr Int Int Int Int Int Int
- data SqlType
- = SqlInteger
- | SqlBigInt
- | SqlSmallInt
- | SqlTinyInt
- | SqlMedInt
- | SqlDecimal Int Int
- | SqlNumeric Int Int
- | SqlReal
- | SqlDouble
- | SqlFloat
- | SqlMoney
- | SqlChar Int
- | SqlVarChar Int
- | SqlLongVarChar Int
- | SqlText
- | SqlWChar Int
- | SqlWVarChar Int
- | SqlWLongVarChar Int
- | SqlDate
- | SqlTime
- | SqlTimeTZ
- | SqlAbsTime
- | SqlRelTime
- | SqlTimeInterval
- | SqlAbsTimeInterval
- | SqlTimeStamp
- | SqlDateTime
- | SqlDateTimeTZ
- | SqlYear
- | SqlBit
- | SqlENUM
- | SqlPoint
- | SqlLSeg
- | SqlPath
- | SqlBox
- | SqlPolygon
- | SqlLine
- | SqlCircle
- | SqlINetAddr
- | SqlCIDRAddr
- | SqlMacAddr
- | SqlBinary Int
- | SqlVarBinary Int
- | SqlLongVarBinary Int
- | SqlSET
- | SqlBLOB
- | SqlUnknown Int
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.
Arguments
| :: Connection | the database connection |
| -> String | the text of SQL command |
| -> IO () |
Submits a command to the database.
Arguments
| :: 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
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
Arguments
| :: Connection | Database 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.
A transaction is to catch ANY exception, so SomeException is adequate.
Utilities
Arguments
| :: (Statement -> s -> IO s) | an action |
| -> Statement | the statement |
| -> s | initial state |
| -> IO s | final state |
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.
SQL Exceptions handling
Constructors
| SqlError | |
Fields
| |
| SqlNoData | |
| SqlInvalidHandle | |
| SqlStillExecuting | |
| SqlNeedData | |
| SqlBadTypeCast | |
Fields
| |
| SqlFetchNull | |
Fields | |
| SqlUnknownField | |
Fields | |
| SqlUnsupportedOperation | |
| SqlClosedHandle | |
catchSql :: IO a -> (SqlError -> IO a) -> IO aSource
DEPRECATED: catchSql: Use Control.Exception.catch instead.
handleSql :: (SqlError -> IO a) -> IO a -> IO aSource
DEPRECATED: handleSql: Use Control.Exception.handle instead.
Casts, if possible, an Exception to an SqlError:
Metadata
Arguments
| :: Connection | Database connection |
| -> IO [String] | The names of all tables in the database. |
List all tables in the database.
Arguments
| :: 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
Extra types
Constructors
| OpenPath [Point] | |
| ClosedPath [Point] |
Differentiation of data types used in DBs.
Constructors
| SqlInteger | |
| SqlBigInt | |
| SqlSmallInt | |
| SqlTinyInt | |
| SqlMedInt | |
| SqlDecimal Int Int | |
| SqlNumeric Int Int | |
| SqlReal | |
| SqlDouble | |
| SqlFloat | |
| SqlMoney | |
| SqlChar Int | |
| SqlVarChar Int | |
| SqlLongVarChar Int | |
| SqlText | |
| SqlWChar Int | |
| SqlWVarChar Int | |
| SqlWLongVarChar Int | |
| SqlDate | |
| SqlTime | |
| SqlTimeTZ | |
| SqlAbsTime | |
| SqlRelTime | |
| SqlTimeInterval | |
| SqlAbsTimeInterval | |
| SqlTimeStamp | |
| SqlDateTime | |
| SqlDateTimeTZ | |
| SqlYear | |
| SqlBit | |
| SqlENUM | |
| SqlPoint | |
| SqlLSeg | |
| SqlPath | |
| SqlBox | |
| SqlPolygon | |
| SqlLine | |
| SqlCircle | |
| SqlINetAddr | |
| SqlCIDRAddr | |
| SqlMacAddr | |
| SqlBinary Int | |
| SqlVarBinary Int | |
| SqlLongVarBinary Int | |
| SqlSET | |
| SqlBLOB | |
| SqlUnknown Int | HSQL returns |