hsql-1.7ContentsIndex
Database.HSQL
Contents
Connect/Disconnect
Command Execution Functions
Retrieving Statement values and types
Transactions
SQL Exceptions handling
Utilities
Metadata
Extra types
Description
Synopsis
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)
data SqlType
= 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
class SqlBind a where
toSqlValue :: a -> String
toSqlValue :: SqlBind a => a -> String
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
data SqlError
= SqlError {
seState :: String
seNativeError :: Int
seErrorMsg :: String
}
| SqlNoData
| SqlInvalidHandle
| SqlStillExecuting
| SqlNeedData
| SqlBadTypeCast {
seFieldName :: String
seFieldType :: SqlType
}
| SqlFetchNull {
seFieldName :: String
}
| SqlUnknownField {
seFieldName :: String
}
| SqlUnsupportedOperation
| SqlClosedHandle
catchSql :: IO a -> (SqlError -> IO a) -> IO a
handleSql :: (SqlError -> IO a) -> IO a -> IO a
sqlExceptions :: Exception -> Maybe SqlError
forEachRow :: (Statement -> s -> IO s) -> Statement -> s -> IO s
forEachRow' :: (Statement -> IO ()) -> Statement -> IO ()
collectRows :: (Statement -> IO a) -> Statement -> IO [a]
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]
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
:: Connectionthe database connection
-> Stringthe 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
:: Connectionthe database connection
-> Stringthe text of SQL query
-> IO Statementthe 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 IntHSQL 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
show/hide Instances
class SqlBind a where
Methods
toSqlValue :: a -> String
show/hide Instances
toSqlValue :: SqlBind a => a -> String
getFieldValue
:: SqlBind a
=> Statement
-> StringField name
-> IO aField value
Retrieves the value of field with the specified name.
getFieldValueMB :: SqlBind a => Statement -> String -> IO (Maybe a)
getFieldValue'
:: SqlBind a
=> Statement
-> StringField name
-> aDefault field value
-> IO aField 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 athe 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
seFieldName :: String
SqlUnknownField
seFieldName :: String
SqlUnsupportedOperation
SqlClosedHandle
show/hide 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
-> Statementthe statement
-> sinitial state
-> IO sfinal 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
:: ConnectionDatabase connection
-> IO [String]The names of all tables in the database.
List all tables in the database.
describe
:: ConnectionDatabase connection
-> StringName 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
Constructors
Point Double Double
show/hide Instances
data Line
Constructors
Line Point Point
show/hide Instances
data Path
Constructors
OpenPath [Point]
ClosedPath [Point]
show/hide Instances
data Box
Constructors
Box Double Double Double Double
show/hide Instances
data Circle
Constructors
Circle Point Double
show/hide Instances
data Polygon
Constructors
Polygon [Point]
show/hide Instances
Produced by Haddock version 0.8