ContentsIndex
Dbconnect
Contents
Connection Creation
Data Manipulation
Select Statements
Exceptions
Tools
Description
Module to connect to a PostgreSQL Database http://www.postgresql.org/
Synopsis
data DBService
createDBService :: String -> String -> String -> String -> String -> Maybe String -> DBService
execute :: DBService -> QueryString -> IO Int
selectReturnTuples :: DBService -> QueryString -> IO [[String]]
selectReturnRow :: DBService -> QueryString -> Int -> IO [String]
selectReturnList :: DBService -> QueryString -> IO [String]
selectReturnOne :: DBService -> QueryString -> IO String
catchDB :: IO a -> (DBException -> IO a) -> IO a
data DBException
= DBError ErrorType String
| Exception
data ErrorType
= ConnectionError
| ExecuteError
setclause :: String -> String -> String
setclausex :: String -> String -> String
escapeQuery :: String -> String
type QueryString = String
Connection Creation
data DBService
createDBService
:: Stringdatabase server, either IP-address or servername
-> Stringname of the database to connect with
-> Stringcommandline options to be sent to the server
-> Stringuser name on server
-> Stringpassword of the user
-> Maybe StringJust pathname specifies location of logfile, Nothing selects default "/tmp/dbconnect.log"
-> DBService
Create an open database handle
Data Manipulation
execute :: DBService -> QueryString -> IO Int
takes a data manipulating statement (insert or update), sends it to the database and returns the number of affected rows
Select Statements
selectReturnTuples :: DBService -> QueryString -> IO [[String]]
Executes a select query, returns the entire result
selectReturnRow :: DBService -> QueryString -> Int -> IO [String]
Executes a select query, returns the ith row
selectReturnList :: DBService -> QueryString -> IO [String]
Executes a select query, returns a list of the first elements of each tuple, the same as do {i <- selectReturnTuples query; return (map head i)}
selectReturnOne :: DBService -> QueryString -> IO String
Executes a select query, returns the first element of the first row, or "" if the result is empty. Useful if the query result is a single value
Exceptions
catchDB :: IO a -> (DBException -> IO a) -> IO a
data DBException
Specifies an Exception which may be thrown by createDBService or any of the DBService functions. Use catchDB to catch this Exception in the main routine. See also: DBConnectExample.
Constructors
DBError ErrorType StringConstructor taking the type of error and a string with a more detailed description
Exception
Instances
Typeable DBException
Show DBException
data ErrorType
Specifies the type of an error, so you can do exception handling depending on the type of exception
Constructors
ConnectionErrorThere's something wrong with the connection: usually the connection is broken
ExecuteErrorThere's something wrong with the query: the execution returns an error
Instances
Typeable ErrorType
Show ErrorType
Tools
setclause
:: Stringcolumnname
-> Stringvalue
-> String
Construct the string: "columname='value' "
setclausex
:: Stringcolumnname
-> Stringvalue
-> String
Construct the string: "columname='value',"
escapeQuery :: String -> String
Escaping a string. Useful to secure untrustworthy user input in forms
type QueryString = String
Produced by Haddock version 0.6