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
:: Either DBError [a] -> IO ()
Print an SQLResult list, i.e., print either the DBError
or the list of result elements.
|
runInTransaction
:: (Connection -> IO (Either DBError a)) -> Connection -> IO (Either DBError a)
Run a DBAction
as a transaction.
|
(>+=)
:: (Connection -> IO (Either DBError a)) -> (a -> Connection -> IO (Either DBError b)) -> Connection -> IO (Either DBError b)
Connect two DBAction s.
|
(>+)
:: (Connection -> IO (Either DBError a)) -> (Connection -> IO (Either DBError b)) -> Connection -> IO (Either DBError b)
Connect two DBActions, but ignore the result of the first. |
fail
:: DBError -> Connection -> IO (Either DBError a)
Failing action. |
ok
:: a -> Connection -> IO (Either DBError a)
Successful action. |
sequenceDBAction
:: [Connection -> IO (Either DBError a)] -> Connection -> IO (Either DBError [a])
Executes a list of DB actions sequentially and returns the list of all results. |
sequenceDBAction_
:: [Connection -> IO (Either DBError a)] -> Connection -> IO (Either DBError ())
Executes a list of DB actions sequentially, ignoring their results. |
mapDBAction
:: (a -> Connection -> IO (Either DBError b)) -> [a] -> Connection -> IO (Either DBError [b])
Applies a function that yields DB actions to all elements of a list, executes the transaction sequentially, and collects their results. |
mapDBAction_
:: (a -> Connection -> IO (Either DBError b)) -> [a] -> Connection -> IO (Either DBError ())
Applies a function that yields DB actions to all elements of a list, executes the transactions sequentially, and ignores their results. |
select
:: String -> [SQLValue] -> [SQLType] -> Connection -> IO (Either DBError [[SQLValue]])
Execute a query where the result of the execution is returned. |
execute
:: String -> [SQLValue] -> Connection -> IO (Either DBError ())
execute a query without a result |
executeMultipleTimes
:: String -> [[SQLValue]] -> Connection -> IO (Either DBError ())
execute 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. |
begin
:: Connection -> IO ()
Begin a transaction. |
commit
:: Connection -> IO ()
Commit a transaction. |
rollback
:: Connection -> IO ()
Rollback a transaction. |
runWithDB
:: String -> (Connection -> IO a) -> IO a
Executes an action dependent on a connection on a database by connecting to the datebase. |
executeRaw
:: String -> [String] -> Connection -> IO (Either DBError [[String]])
Execute a SQL statement. |
getColumnNames
:: String -> Connection -> IO (Either DBError [String])
Returns a list with the names of every column in a table The parameter is the name of the table and a connection |
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 returns an IO (SQLResult a)
.
Type synonym: DBAction a = Connection -> IO (SQLResult a)
Data type for database connections. Currently, only connections to a SQLite3 database are supported, but other types of connections could easily be added. List of functions that would need to be implemented: 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 |
Run a
|
Connect two
|
Connect two DBActions, but ignore the result of the first. |
Failing action.
|
Successful action.
|
Executes a list of DB actions sequentially and returns the list of all results. |
Executes a list of DB actions sequentially, ignoring their results. |
Applies a function that yields DB actions to all elements of a list, executes the transaction sequentially, and collects their results. |
Applies a function that yields DB actions to all elements of a list, executes the transactions sequentially, and ignores their results. |
Execute a query where the result of the execution is returned.
|
execute a query without a result
|
execute a query multiple times with different SQLValues without a result
|
Connect to a SQLite Database
|
Disconnect from a database. |
Begin a transaction. |
Commit a transaction. |
Rollback a transaction. |
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.
|
Execute a 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 and a connection |
|