hsql-1.8.2: Database access from Haskell.

Safe HaskellNone

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.

Metadata

tablesSource

Arguments

:: Connection

Database connection

-> IO [TableId]

The names of all tables in the database.

List all tables in the database.

type ColDef = (ColId, SqlType, Nullability)Source

Description of the properties of a table column.

describeSource

Arguments

:: Connection

Database connection

-> TableId

Name of a database table

-> IO [ColDef]

The list of fields in the table

List all columns in a table along with their types and nullable flags

Command Execution Functions

type SQL = StringSource

An SQL Query.

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

-> SQL

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

-> SQL

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

class SqlBind a whereSource

Equivalent to Show and Read adapted to SQL expressions.

Methods

fromSqlCStringLenSource

Arguments

:: ColDef 
-> CString

binary content of SQL expression

-> Int

size of binary content

-> IO a 

read from SQL expression in binary representation, by support of its ColDef and code size info. This allows for faster conversion for e.g. integral numeric types, etc.

getFieldValueSource

Arguments

:: SqlBind a 
=> Statement

result table data

-> String

field name

-> IO a

field value

Retrieves the value of field with the specified name.

getFieldValueMB :: SqlBind a => Statement -> String -> IO (Maybe a)Source

Deprecated: Use getFieldValue instead.

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

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

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.

SQL Exceptions handling

data SqlError Source

Constructors

SqlError

generic error condition, with further specification

SqlNoMoreData

no more data was available

SqlInvalidHandle

requested handle is invalid

SqlStillExecuting

connection is blocked by running transaction

SqlNeedMoreData

more data is needed, e.g. additional connection specs

SqlBadTypeCast

requested field can't be converted to requested type

SqlFetchNull

requested field returns NULL

Fields

seFieldName :: String
 
SqlUnknownField

requested field isn't known

Fields

seFieldName :: String
 
SqlUnsupportedOperation

requested operation isn't supported

SqlClosedHandle

referenced handle is already closed

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

Deprecated: Use Control.Exception.catch instead.

Deprecated: Use catch instead.

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

Deprecated: Use Control.Exception.handle instead.

Deprecated: Use handle instead.

sqlExceptionsSource

Arguments

:: Exception x 
=> x

the exception thinc to be cast

-> Maybe SqlError 

Casts, if possible, an Exception to an SqlError.

Extra types

data Point Source

A 2D point.

Constructors

Point 

Fields

pointX :: Double
 
pointY :: Double
 

data Line Source

A 2D straight line.

Constructors

Line 

Fields

lineBegin :: Point
 
lineEnd :: Point
 

data Path Source

A 2D path, either open, or closed (looping).

Constructors

OpenPath

An open path

Fields

pathPoints :: [Point]
 
ClosedPath

A looping path

Fields

pathPoints :: [Point]
 

data Box Source

A 2D rectangle.

Constructors

Box 

Fields

boxX1 :: Double
 
boxY1 :: Double
 
boxX2 :: Double
 
boxY2 :: Double
 

Instances

data Circle Source

A 2D circle

Constructors

Circle 

data Polygon Source

A 2D polygon (without holes).

Constructors

Polygon 

Fields

polygonPoints :: [Point]
 

data INetAddr Source

An IP4 address with netmask in CIDR notation.

Constructors

INetAddr 

data MacAddr Source

A MAC network address.

Constructors

MacAddr 

data SqlType Source

Variety of common data types used in databases.

Constructors

SqlInteger 
SqlBigInt 
SqlSmallInt 
SqlTinyInt 
SqlMedInt 
SqlDecimal 

Fields

typeSize :: Int
 
typeDecimals :: Int
 
SqlNumeric 

Fields

typeSize :: Int
 
typeDecimals :: Int
 
SqlReal 
SqlDouble 
SqlFloat 
SqlMoney 
SqlChar 

Fields

typeSize :: Int
 
SqlVarChar 

Fields

typeSize :: Int
 
SqlLongVarChar 

Fields

typeSize :: Int
 
SqlText 
SqlWChar 

Fields

typeSize :: Int
 
SqlWVarChar 

Fields

typeSize :: Int
 
SqlWLongVarChar 

Fields

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

Fields

typeSize :: Int
 
SqlVarBinary 

Fields

typeSize :: Int
 
SqlLongVarBinary 

Fields

typeSize :: Int
 
SqlSET 
SqlBLOB 
SqlUnknown

HSQL returns SqlUnknown for all columns for which it cannot determine the right type. The backendTypeCode here is the internal type code returned from the backend library

Fields

typeCode :: Int