|
Database.HSQL | Portability | portable | Stability | provisional | Maintainer | ka2_mail@yahoo.com |
|
|
|
|
|
Description |
The module provides an abstract database interface
|
|
Synopsis |
|
|
|
|
Connect/Disconnect |
|
data Connection |
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 () |
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. |
|
execute |
:: Connection | the database connection | -> String | the text of SQL command | -> IO () | | Submits a command to the database. |
|
|
data Statement |
The Statement type represents a result from the execution of given SQL query. |
|
|
query |
:: Connection | the database connection | -> String | the text of SQL query | -> IO Statement | the associated statement. Must be closed with
the closeStatement function | Executes a query and returns a result set |
|
|
closeStatement :: Statement -> IO () |
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 Bool |
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 |
|
type FieldDef = (String, SqlType, Bool) |
|
data SqlType |
Constructors | 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 SqlUnknown tp for all
columns for which it cannot determine
the right type. The tp here is the
internal type code returned from the
backend library |
| Instances | |
|
|
class SqlBind a |
|
|
toSqlValue :: SqlBind a => a -> String |
|
getFieldValueMB |
:: SqlBind a | | => Statement | | -> String | Field name | -> IO (Maybe a) | Field value or Nothing | Retrieves the value of field with the specified name.
The returned value is Nothing if the field value is null. |
|
|
getFieldValue |
:: SqlBind a | | => Statement | | -> String | Field name | -> IO a | Field value | Retrieves the value of field with the specified name.
If the field value is null then the function will throw SqlFetchNull exception. |
|
|
getFieldValue' |
:: SqlBind a | | => Statement | | -> String | Field name | -> a | Default field value | -> IO a | Field value | 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) |
Returns the type and the nullable flag for field with specified name |
|
getFieldsTypes :: Statement -> [(String, SqlType, Bool)] |
Returns the list of fields with their types and nullable flags |
|
Transactions |
|
inTransaction |
:: 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 |
|
data SqlError |
Constructors | SqlError | | seState :: String | | seNativeError :: Int | | seErrorMsg :: String | |
| SqlNoData | | SqlInvalidHandle | | SqlStillExecuting | | SqlNeedData | | SqlBadTypeCast | | seFieldName :: String | | seFieldType :: SqlType | |
| SqlFetchNull | | | SqlUnknownField | | | SqlUnsupportedOperation | | SqlClosedHandle | |
| Instances | |
|
|
catchSql :: IO a -> (SqlError -> IO a) -> IO a |
|
handleSql :: (SqlError -> IO a) -> IO a -> IO a |
|
sqlExceptions :: Exception -> Maybe SqlError |
|
Utilities |
|
forEachRow |
:: (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 () |
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] |
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 |
|
tables |
:: Connection | Database connection | -> IO [String] | The names of all tables in the database. | List all tables in the database. |
|
|
describe |
:: 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 |
|
data Point |
|
|
data Line |
|
|
data Path |
|
|
data Box |
Constructors | Box Double Double Double Double | |
| Instances | |
|
|
data Circle |
|
|
data Polygon |
|
|
Produced by Haddock version 0.6 |