This module defines basis data types and functions for accessing database systems using SQL. Currently, only SQLite3 is supported, but this is easy to extend. It also provides execution of SQL-Queries with types. Allowed datatypes for these queries are defined and the conversion to standard SQL-Queries is provided.
Author: Mike Tallarek, Michael Hanus
fromSQLResult
:: Either DBError a -> a
Gets the value of an SQLResult .
|
printSQLResults
:: Show a => Either DBError [a] -> IO ()
Print an SQLResult list, i.e., print either the DBError
or the list of result elements.
|
runDBAction
:: DBAction a -> Connection -> IO (Either DBError a)
Runs a DBAction
on a connection.
|
runInTransaction
:: DBAction a -> DBAction a
Run a DBAction
as a transaction.
|
(>+=)
:: DBAction a -> (a -> DBAction b) -> DBAction b
Connects two DBAction s.
|
(>+)
:: DBAction a -> DBAction b -> DBAction b
Connects two DBAction s but ignore the result of the first.
|
returnDB
:: Either DBError a -> DBAction a
Returns an SQLResult .
|
failDB
:: DBError -> DBAction a
A failed DBAction
with a specific error.
|
select
:: String -> [SQLValue] -> [SQLType] -> DBAction [[SQLValue]]
Execute a query where the result of the execution is returned. |
execute
:: String -> [SQLValue] -> DBAction ()
execute a query without a result |
executeMultipleTimes
:: String -> [[SQLValue]] -> DBAction ()
Executes a query multiple times with different SQLValues without a result |
connectSQLite
:: String -> IO Connection
Connect to a SQLite Database |
disconnect
:: Connection -> IO ()
Disconnect from a database. |
writeConnection
:: String -> Connection -> IO ()
Write a String
to a Connection .
|
begin
:: DBAction ()
Begin a transaction. |
commit
:: DBAction ()
Commit a transaction. |
rollback
:: DBAction ()
Rollback a transaction. |
setForeignKeyCheck
:: Bool -> DBAction ()
Turn on/off checking of foreign key constraints (SQLite3). |
runWithDB
:: String -> DBAction a -> IO (Either DBError a)
Executes an action dependent on a connection on a database by connecting to the datebase. |
executeRaw
:: String -> [String] -> DBAction [[String]]
Executes an SQL statement. |
getColumnNames
:: String -> DBAction [String]
Returns a list with the names of every column in a table The parameter is the name of the table. |
valueToString
:: SQLValue -> String
|
The result of SQL-related actions. It is either a DBError
or some value.
Type synonym: SQLResult a = Either DBError a
DBError
s are composed of an DBErrorKind
and a String
describing the error more explicitly.
Constructors:
DBError
:: DBErrorKind -> String -> DBError
The different kinds of errors.
Constructors:
TableDoesNotExist
:: DBErrorKind
ParameterError
:: DBErrorKind
ConstraintViolation
:: DBErrorKind
SyntaxError
:: DBErrorKind
NoLineError
:: DBErrorKind
LockedDBError
:: DBErrorKind
UnknownError
:: DBErrorKind
Data type for SQL values, used during the communication with the database.
Constructors:
SQLString
:: String -> SQLValue
SQLInt
:: Int -> SQLValue
SQLFloat
:: Float -> SQLValue
SQLChar
:: Char -> SQLValue
SQLBool
:: Bool -> SQLValue
SQLDate
:: ClockTime -> SQLValue
SQLNull
:: SQLValue
Type identifiers for SQLValue
s, necessary to determine the type
of the value a column should be converted to.
Constructors:
SQLTypeString
:: SQLType
SQLTypeInt
:: SQLType
SQLTypeFloat
:: SQLType
SQLTypeChar
:: SQLType
SQLTypeBool
:: SQLType
SQLTypeDate
:: SQLType
A DBAction
takes a connection and performs an IO action that
returns a SQLResult a
value.
Constructors:
Data type for database connections. Currently, only connections to a SQLite3 database are supported, but other types of connections could easily be added. The following functions might need to be re-implemented for other DBs: A function to connect to the database, disconnect, writeConnection readRawConnectionLine, parseLines, begin, commit, rollback, and getColumnNames
Constructors:
SQLiteConnection
:: Handle -> Connection
Gets the value of an |
Print an |
Runs a |
Run a
|
Connects two
|
Connects two
|
Execute a query where the result of the execution is returned.
|
execute a query without a result
|
Executes a query multiple times with different SQLValues without a result
|
Connect to a SQLite Database
|
Disconnect from a database. |
Write a |
Begin a transaction. Inside a transaction, foreign key constraints are checked. |
Turn on/off checking of foreign key constraints (SQLite3). |
Executes an action dependent on a connection on a database by connecting to the datebase. The connection will be kept open and re-used for the next action to this database.
|
Executes an SQL statement.
The statement may contain |
Returns a list with the names of every column in a table The parameter is the name of the table. |
|