MetaHDBC-0.1.2: Statically checked database access

Database.MetaHDBC.SqlExpr

Contents

Synopsis

Documentation

runStmtSource

Arguments

:: String

Data source name (DSN)

-> String

SQL statement extended with question marks for parameteres

-> ExpQ

The expression has type Connection -> a1 -> ... -> an -> IO [x1, ... xm]), where a1-an are inputs to the statement (due to placeholder arguments), and x1-xm are the outputs from the statement.

If there are no outputs from the statement (e.g. an insert statement) the number of affected rows is returned.

Statically typed one-off (not prepared) SQL statement.

prepareStmtSource

Arguments

:: String

Data source name (DSN)

-> String

SQL statement extended with question marks for parameteres

-> ExpQ

The expression has type Connection -> IO (a1 -> ... -> an -> IO [x1, ... xm]), where a1-an are inputs to the statement (due to placeholder arguments), and x1-xm are the outputs from the statement.

If there are no outputs from the statement (e.g. an insert statement) the number of affected rows is returned.

Statically typed prepared SQL statement.

strict :: IO [a] -> IO [a]Source

Makes the query result from prepareStmt or runStmt strict.

data ExprParts Source

Common parts for both statements run directly (runStmt) and prepared statements.

Constructors

ExprParts 

Fields

parameters :: [Parameter]

Positional parameters

returnTypes :: [SqlColDesc]

Description of values returned from a SQL statement

dbSqlExpr :: String

The SQL expression which is passed on to the database

connectionName :: Name

Name of the Connection parameter.

data Parameter Source

Describing a positional parameter

Constructors

Parameter 

data PrepareParts Source

Parts used in prepared statements

Constructors

PrepareParts 

sqlInfo :: String -> String -> IO StringSource

Returns textual information about a query. The returned String is useful as presentation to a user, not for further processing.

makeExprParts :: String -> String -> Q ExprPartsSource

Contructs expression-parts. A database is contacting to parse the SQL and infer correct types.

Helper functions to construct directly runned statements (runStmt)

runStmtLHSSource

Arguments

:: ExprParts 
-> ExpQ

Expression which is expected to access the database

-> ExpQ 

Constructs a lambda which given a connection and parameters will execute expr. See runStmtRHS.

runStmtRHS :: ExprParts -> ExpQSource

Creates an exprresion which runs a SQL statement on a database server. It is expected that the connection variable and parameters has already been bound. See also runStmtLHS.

Helper function to construct prepared statements

makePrepStmtParts :: String -> String -> Q PreparePartsSource

Creates parts for a prepared statement. Calls makeExprParts.

prepStmtLHS :: PrepareParts -> [StmtQ] -> ExpQSource

Lambda for prepared statements.

prepStmtQ :: PrepareParts -> StmtQSource

A StmtQ which prepares a statement on a database.

execPrepStmtRHS :: PrepareParts -> StmtQSource

A StmtQ to execute a statement on a database.

returnExecPrepStmtLHS :: PrepareParts -> [StmtQ] -> StmtQSource

Creates a StmtQ of type: IO (a1-an -> IO ... ). Where a1-an are the parameters which must be bound.