hsql-1.7.1: Simple library for database access from Haskell.

Database.HSQL

Contents

Description

 

Synopsis

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.

executeSource

Arguments

:: Connection

the database connection

-> String

the text of SQL command

-> IO () 

Submits a command to the database.

data Statement Source

The Statement type represents a result from the execution of given SQL query.

querySource

Arguments

:: 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 ()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

getFieldValueSource

Arguments

:: SqlBind a 
=> Statement 
-> String

Field name

-> IO a

Field value

Retrieves the value of field with the specified name.

getFieldValue'Source

Arguments

:: 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)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

inTransactionSource

Arguments

:: 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

catchSql :: IO a -> (SqlError -> IO a) -> IO aSource

handleSql :: (SqlError -> IO a) -> IO a -> IO aSource

Utilities

forEachRowSource

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.

Metadata

tablesSource

Arguments

:: Connection

Database connection

-> IO [String]

The names of all tables in the database.

List all tables in the database.

describeSource

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

data Point Source

Constructors

Point Double Double 

data Line Source

Constructors

Line Point Point 

Instances

data Path Source

Constructors

OpenPath [Point] 
ClosedPath [Point] 

Instances

data Box Source

Constructors

Box Double Double Double Double 

Instances

data Circle Source

Constructors

Circle Point Double 

data Polygon Source

Constructors

Polygon [Point]