hsql-1.8.2: Database access from Haskell.

Safe Haskell | None

Database.HSQL.Types

Description

Basic type class & type definitions for DB interfacing.

Synopsis

- type SQL = String
- type TableId = String
- data Connection = Connection {
  - connDisconnect :: IO ()
  - connExecute :: SQL -> IO ()
  - connQuery :: SQL -> IO Statement
  - connTables :: IO [TableId]
  - connDescribe :: TableId -> IO [ColDef]
  - connBeginTransaction :: IO ()
  - connCommitTransaction :: IO ()
  - connRollbackTransaction :: IO ()
  - connClosed :: MVar Bool
  }
- type ColId = String
- type Nullability = Bool
- type ColDef = (ColId, SqlType, Nullability)
- type FieldReader t = ColDef -> CString -> Int -> IO t
- type FieldReading = forall t. Int -> ColDef -> FieldReader t -> IO t
- data Statement = Statement {
  - stmtConn :: Connection
  - stmtClose :: IO ()
  - stmtFetch :: IO Bool
  - stmtGetCol :: FieldReading
  - stmtFields :: [ColDef]
  - stmtClosed :: MVar Bool
  }
- class SqlBind a where
  - toSqlValue :: a -> SQL
  - fromSqlValue :: SqlType -> SQL -> Maybe a
  - fromSqlCStringLen :: ColDef -> CString -> Int -> IO a
- data SqlType
  - = SqlInteger
  - | SqlBigInt
  - | SqlSmallInt
  - | SqlTinyInt
  - | SqlMedInt
  - | SqlDecimal {
    - typeSize :: Int
    - typeDecimals :: Int
    }
  - | SqlNumeric {
    - typeSize :: Int
    - typeDecimals :: Int
    }
  - | SqlReal
  - | SqlDouble
  - | SqlFloat
  - | SqlMoney
  - | SqlChar {
    - typeSize :: Int
    }
  - | SqlVarChar {
    - typeSize :: Int
    }
  - | SqlLongVarChar {
    - typeSize :: Int
    }
  - | SqlText
  - | SqlWChar {
    - typeSize :: Int
    }
  - | SqlWVarChar {
    - typeSize :: Int
    }
  - | SqlWLongVarChar {
    - 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 {
    - typeSize :: Int
    }
  - | SqlVarBinary {
    - typeSize :: Int
    }
  - | SqlLongVarBinary {
    - typeSize :: Int
    }
  - | SqlSET
  - | SqlBLOB
  - | SqlUnknown {
    - typeCode :: Int
    }
- data SqlError
  - = SqlError {
    - seState :: String
    - seNativeError :: Int
    - seErrorMsg :: String
    }
  - | SqlNoMoreData
  - | SqlInvalidHandle
  - | SqlStillExecuting
  - | SqlNeedMoreData
  - | SqlBadTypeCast {
    - seFieldName :: String
    - seFieldType :: SqlType
    }
  - | SqlFetchNull {
    - seFieldName :: String
    }
  - | SqlUnknownField {
    - seFieldName :: String
    }
  - | SqlUnsupportedOperation
  - | SqlClosedHandle

# Documentation

type SQL = String Source

An SQL Query.

type TableId = String Source

A table ID.

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.

Constructors

Connection |

Fields

connDisconnect :: IO ()

  disconnect action

connExecute :: SQL -> IO ()

  query execution action (without return value)

connQuery :: SQL -> IO Statement

  query action with return value

connTables :: IO [TableId]

  retrieval of the names of the tables in reach

connDescribe :: TableId -> IO [ColDef]

  retrieval of the field defs of a table

connBeginTransaction :: IO ()

  begin of a transaction

connCommitTransaction :: IO ()

  commit of a pending transaction

connRollbackTransaction :: IO ()

  rollback of a pending transaction

connClosed :: MVar Bool

  closing state of the connection

type ColId = String Source

A table column ID.

type Nullability = Bool Source

Whether fields of a table col may be NULL.

type ColDef = (ColId, SqlType, Nullability)Source

Description of the properties of a table column.

type FieldReader tSource

Arguments

= ColDef | field type spec
-> CString | field content code
-> Int | field content length
-> IO t | field read action

A DB generic field extraction function, specifiable by field definition, receiving the content code and its length.

type FieldReading Source

Arguments

= forall t . |
=> Int | field (column) index
-> ColDef | source field type spec
-> FieldReader t | field reader to be applied
-> IO t | field read action

An extraction of a field of type to be specified by requester, from a row index with source `ColDef`, applying an appropriate `FieldReader`.

data Statement Source

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

Constructors

Statement |

Fields

stmtConn :: Connection

  DB connection the statement depends on

stmtClose :: IO ()

  close action

stmtFetch :: IO Bool

  incrementation of the row pointer and indication whether this is still in range of available rows

stmtGetCol :: FieldReading

  a `FieldReading` function applicable for each row

stmtFields :: [ColDef]

  field descriptors for each result table column

stmtClosed :: MVar Bool

  check whether the statement is closed

class SqlBind a where Source

Equivalent to Show and Read adapted to SQL expressions.

Methods

toSqlValue :: a -> SQL Source

show as an SQL expression

fromSqlValue :: SqlType -> SQL -> Maybe aSource

read from an SQL expression in text representation, by support of its `SqlType`

fromSqlCStringLen Source

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.

Instances

SqlBind Bool |
SqlBind Double |
SqlBind Float |
SqlBind Int |
SqlBind Int64 |
SqlBind Integer |
SqlBind String |
SqlBind ClockTime |
SqlBind Circle |
SqlBind Polygon |
SqlBind Box |
SqlBind Path |
SqlBind Line |
SqlBind Point |
SqlBind MacAddr |
SqlBind INetAddr |
SqlBind a => SqlBind (Maybe a) |

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

Instances

Eq SqlType |
Ord SqlType |
Read SqlType |
Show SqlType |

data SqlError Source

Constructors

SqlError | generic error condition, with further specification

Fields

seState :: String
seNativeError :: Int
seErrorMsg :: String

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

Fields

seFieldName :: String
seFieldType :: SqlType

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

Instances

Eq SqlError |
Ord SqlError |
Show SqlError |
Typeable SqlError |
Exception SqlError |