Module Database.CDBI.Criteria

This module provides datatypes, constructor functions and translation functions to specify SQL criteria including options(group-by, having, order-by)

Author: Mike Tallarek, Julia Krone

Version: 0.2

Summary of exported operations:

emptyCriteria :: Criteria   
An empty criteria
int :: Int -> Value Int   
Constructor for a Value Val of type Int
float :: Float -> Value Float   
Constructor for a Value Val of type Float
char :: Char -> Value Char   
Constructor for a Value Val of type Char
string :: String -> Value String   
Constructor for a Value Val of type String
bool :: Bool -> Value Bool   
Constructor for a Value Val of type Bool
date :: ClockTime -> Value ClockTime   
Constructor for a Value Val of type ClockTime
idVal :: Int -> Value a   
Constructor for Values of ID-types Should just be used internally!
col :: Column a -> Value a   
Constructor for a Value Col without a rename-number
colNum :: Column a -> Int -> Value a   
Constructor for a Value Col with a rename-number
colVal :: Column a -> Value a -> ColVal   
A constructor for ColVal needed for typesafety
colValAlt :: String -> String -> SQLValue -> ColVal   
Alternative ColVal constructor without typesafety
isNull :: Value a -> Constraint   
IsNull construnctor
isNotNull :: Value a -> Constraint   
IsNotNull construnctor
equal :: Value a -> Value a -> Constraint   
Equal construnctor
(.=.) :: Value a -> Value a -> Constraint   
Infix Equal
notEqual :: Value a -> Value a -> Constraint   
NotEqual construnctor
(./=.) :: Value a -> Value a -> Constraint   
Infix NotEqual
greaterThan :: Value a -> Value a -> Constraint   
GreatherThan construnctor
(.>.) :: Value a -> Value a -> Constraint   
Infix GreaterThan
lessThan :: Value a -> Value a -> Constraint   
LessThan construnctor
(.<.) :: Value a -> Value a -> Constraint   
Infix LessThan
greaterThanEqual :: Value a -> Value a -> Constraint   
GreaterThanEqual construnctor
(.>=.) :: Value a -> Value a -> Constraint   
Infix GreaterThanEqual
lessThanEqual :: Value a -> Value a -> Constraint   
LessThanEqual construnctor
(.<=.) :: Value a -> Value a -> Constraint   
Infix LessThanEqual
like :: Value a -> Value a -> Constraint   
Like construnctor
(.~.) :: Value a -> Value a -> Constraint   
Infix Like
between :: Value a -> Value a -> Value a -> Constraint   
Between construnctor
isIn :: Value a -> [Value a] -> Constraint   
IsIn construnctor
(.<->.) :: Value a -> [Value a] -> Constraint   
Infix IsIn
ascOrder :: Value a -> Option   
Constructor for the option: Ascending Order by Column
descOrder :: Value a -> Option   
Constructor for the option: Descending Order by Column
groupBy :: Value a -> GroupByTail -> GroupBy   
groupByCol :: Value a -> GroupByTail -> GroupByTail   
Constructor to specifiy more than one column for group-by
having :: Condition -> GroupByTail   
noHave :: GroupByTail   
Constructor for empty having-Clause
condition :: Constraint -> Condition   
sumIntCol :: Specifier -> Value Int -> Value Int -> (Value () -> Value () -> Constraint) -> Condition   
having-clauses.
sumFloatCol :: Specifier -> Value Float -> Value Float -> (Value () -> Value () -> Constraint) -> Condition   
Constructor for aggregation function sum for columns of type float in having-clauses.
avgIntCol :: Specifier -> Value Int -> Value Float -> (Value () -> Value () -> Constraint) -> Condition   
Constructor for aggregation function avg for columns of type Int in having-clauses.
avgFloatCol :: Specifier -> Value Float -> Value Float -> (Value () -> Value () -> Constraint) -> Condition   
Constructor for aggregation function avg for columns of type float in having-clauses.
countCol :: Specifier -> Value a -> Value Int -> (Value () -> Value () -> Constraint) -> Condition   
minCol :: Specifier -> Value a -> Value a -> (Value () -> Value () -> Constraint) -> Condition   
Constructor for aggregation function min in having-clauses.
maxCol :: Specifier -> Value a -> Value a -> (Value () -> Value () -> Constraint) -> Condition   
Constructor for aggregation function max in having-clauses.
toCColumn :: Column a -> Column ()   
toCValue :: Value a -> Value ()   
trCriteria :: Criteria -> String   
trOption :: [Option] -> String   
trCondition :: Condition -> String   
trConstraint :: Constraint -> String   
trValue :: Value a -> String   
trColumn :: String -> Int -> String   
trSpecifier :: Specifier -> String   

Exported datatypes:


Criteria

Criterias for queries that can have a constraint and a group-by clause

Constructors:


Specifier

specifier for queries

Constructors:

  • Distinct :: Specifier
  • All :: Specifier

Option

datatype to represent order-by statement

Constructors:


GroupBy

datatype to represent group-by statement

Constructors:


Condition

datatype for conditions inside a having-clause

Constructors:


Value

A datatype to compare values. Can be either a SQLValue or a Column with an additional Integer (rename-number). The Integer is for dealing with renamed tables in queries (i.e. Students as 1Students). If the Integer n is 0 the column will be named as usual ("Table"."Column"), otherwise it will be named "nTable"."Column" in the query This is for being able to do complex "where exists" constraints

Constructors:


ColVal

A datatype thats a combination between a Column and a Value (Needed for update queries)

Constructors:


CColumn

Type for columns used inside a constraint.

Type synonym: CColumn = Column ()


CValue

Type for values used inside a constraint.

Type synonym: CValue = Value ()


Constraint

Constraints for queries Every constructor with at least one value has a function as a constructor and only that function will be exported to assure type-safety Most of these are just like the Sql-where-commands Exists needs the table-name, an integer and maybe a constraint (where exists (select from table where constraint)) The integer n will rename the table if it has a different value than 0 (where exists (select from table as ntable where...))

Constructors:


Exported operations:

emptyCriteria :: Criteria   

An empty criteria

Further infos:
  • solution complete, i.e., able to compute all solutions

int :: Int -> Value Int   

Constructor for a Value Val of type Int

Example call:
(int i)
Parameters:
  • i : The value

float :: Float -> Value Float   

Constructor for a Value Val of type Float

Example call:
(float i)
Parameters:
  • i : The value

char :: Char -> Value Char   

Constructor for a Value Val of type Char

Example call:
(char i)
Parameters:
  • i : The value

string :: String -> Value String   

Constructor for a Value Val of type String

Example call:
(string i)
Parameters:
  • i : The value

bool :: Bool -> Value Bool   

Constructor for a Value Val of type Bool

Example call:
(bool i)
Parameters:
  • i : The value

date :: ClockTime -> Value ClockTime   

Constructor for a Value Val of type ClockTime

Example call:
(date i)
Parameters:
  • i : The value

idVal :: Int -> Value a   

Constructor for Values of ID-types Should just be used internally!

Further infos:
  • solution complete, i.e., able to compute all solutions

col :: Column a -> Value a   

Constructor for a Value Col without a rename-number

Example call:
(col c)
Parameters:
  • c : The column
Further infos:
  • solution complete, i.e., able to compute all solutions

colNum :: Column a -> Int -> Value a   

Constructor for a Value Col with a rename-number

Example call:
(colNum c n)
Parameters:
  • c : The column
  • n : The rename-number
Further infos:
  • solution complete, i.e., able to compute all solutions

colVal :: Column a -> Value a -> ColVal   

A constructor for ColVal needed for typesafety

Example call:
(colVal c v)
Parameters:
  • c : The Column
  • v : The Value
Further infos:
  • solution complete, i.e., able to compute all solutions

colValAlt :: String -> String -> SQLValue -> ColVal   

Alternative ColVal constructor without typesafety

Example call:
(colValAlt table cl s)
Parameters:
  • table : The Tablename of the column
  • cl : The column name
  • s : The SQLValue
Further infos:
  • solution complete, i.e., able to compute all solutions

isNull :: Value a -> Constraint   

IsNull construnctor

Example call:
(isNull v1)
Parameters:
  • v1 : First Value
Further infos:
  • solution complete, i.e., able to compute all solutions

isNotNull :: Value a -> Constraint   

IsNotNull construnctor

Example call:
(isNotNull v1)
Parameters:
  • v1 : First Value
Further infos:
  • solution complete, i.e., able to compute all solutions

equal :: Value a -> Value a -> Constraint   

Equal construnctor

Example call:
(equal v1 v2)
Parameters:
  • v1 : First Value
  • v2 : Second Value
Further infos:
  • solution complete, i.e., able to compute all solutions

(.=.) :: Value a -> Value a -> Constraint   

Infix Equal

Further infos:
  • solution complete, i.e., able to compute all solutions

notEqual :: Value a -> Value a -> Constraint   

NotEqual construnctor

Example call:
(notEqual v1 v2)
Parameters:
  • v1 : First Value
  • v2 : Second Value
Further infos:
  • solution complete, i.e., able to compute all solutions

(./=.) :: Value a -> Value a -> Constraint   

Infix NotEqual

Further infos:
  • solution complete, i.e., able to compute all solutions

greaterThan :: Value a -> Value a -> Constraint   

GreatherThan construnctor

Example call:
(greaterThan v1 v2)
Parameters:
  • v1 : First Value
  • v2 : Second Value
Further infos:
  • solution complete, i.e., able to compute all solutions

(.>.) :: Value a -> Value a -> Constraint   

Infix GreaterThan

Further infos:
  • solution complete, i.e., able to compute all solutions

lessThan :: Value a -> Value a -> Constraint   

LessThan construnctor

Example call:
(lessThan v1 v2)
Parameters:
  • v1 : First Value
  • v2 : Second Value
Further infos:
  • solution complete, i.e., able to compute all solutions

(.<.) :: Value a -> Value a -> Constraint   

Infix LessThan

Further infos:
  • solution complete, i.e., able to compute all solutions

greaterThanEqual :: Value a -> Value a -> Constraint   

GreaterThanEqual construnctor

Example call:
(greaterThanEqual v1 v2)
Parameters:
  • v1 : First Value
  • v2 : Second Value
Further infos:
  • solution complete, i.e., able to compute all solutions

(.>=.) :: Value a -> Value a -> Constraint   

Infix GreaterThanEqual

Further infos:
  • solution complete, i.e., able to compute all solutions

lessThanEqual :: Value a -> Value a -> Constraint   

LessThanEqual construnctor

Example call:
(lessThanEqual v1 v2)
Parameters:
  • v1 : First Value
  • v2 : Second Value
Further infos:
  • solution complete, i.e., able to compute all solutions

(.<=.) :: Value a -> Value a -> Constraint   

Infix LessThanEqual

Further infos:
  • solution complete, i.e., able to compute all solutions

like :: Value a -> Value a -> Constraint   

Like construnctor

Example call:
(like v1 v2)
Parameters:
  • v1 : First Value
  • v2 : Second Value
Further infos:
  • solution complete, i.e., able to compute all solutions

(.~.) :: Value a -> Value a -> Constraint   

Infix Like

Further infos:
  • solution complete, i.e., able to compute all solutions

between :: Value a -> Value a -> Value a -> Constraint   

Between construnctor

Example call:
(between v1 v2 v3)
Parameters:
  • v1 : First Value
  • v2 : Second Value
  • v3 : Third Value
Further infos:
  • solution complete, i.e., able to compute all solutions

isIn :: Value a -> [Value a] -> Constraint   

IsIn construnctor

Example call:
(isIn v1 xs)
Parameters:
  • v1 : First Value
  • xs : List of Values

(.<->.) :: Value a -> [Value a] -> Constraint   

Infix IsIn

ascOrder :: Value a -> Option   

Constructor for the option: Ascending Order by Column

Example call:
(ascOrder c)
Parameters:
  • c : The Column that should be ordered by
Further infos:
  • solution complete, i.e., able to compute all solutions

descOrder :: Value a -> Option   

Constructor for the option: Descending Order by Column

Example call:
(descOrder c)
Parameters:
  • c : The Column that should be ordered by
Further infos:
  • solution complete, i.e., able to compute all solutions

groupBy :: Value a -> GroupByTail -> GroupBy   

Further infos:
  • solution complete, i.e., able to compute all solutions

groupByCol :: Value a -> GroupByTail -> GroupByTail   

Constructor to specifiy more than one column for group-by

Example call:
(groupByCol c gbTail)
Parameters:
  • c : the additional column
  • gbTail : subsequent part of group-by statement
Further infos:
  • solution complete, i.e., able to compute all solutions

having :: Condition -> GroupByTail   

Further infos:
  • solution complete, i.e., able to compute all solutions

noHave :: GroupByTail   

Constructor for empty having-Clause

Further infos:
  • solution complete, i.e., able to compute all solutions

condition :: Constraint -> Condition   

Further infos:
  • solution complete, i.e., able to compute all solutions

sumIntCol :: Specifier -> Value Int -> Value Int -> (Value () -> Value () -> Constraint) -> Condition   

having-clauses.

sumFloatCol :: Specifier -> Value Float -> Value Float -> (Value () -> Value () -> Constraint) -> Condition   

Constructor for aggregation function sum for columns of type float in having-clauses.

avgIntCol :: Specifier -> Value Int -> Value Float -> (Value () -> Value () -> Constraint) -> Condition   

Constructor for aggregation function avg for columns of type Int in having-clauses.

avgFloatCol :: Specifier -> Value Float -> Value Float -> (Value () -> Value () -> Constraint) -> Condition   

Constructor for aggregation function avg for columns of type float in having-clauses.

countCol :: Specifier -> Value a -> Value Int -> (Value () -> Value () -> Constraint) -> Condition   

minCol :: Specifier -> Value a -> Value a -> (Value () -> Value () -> Constraint) -> Condition   

Constructor for aggregation function min in having-clauses.

Example call:
(minCol spec)
Parameters:
  • spec : specifier Distinct or All

maxCol :: Specifier -> Value a -> Value a -> (Value () -> Value () -> Constraint) -> Condition   

Constructor for aggregation function max in having-clauses.

Example call:
(maxCol spec)
Parameters:
  • spec : specifier Distinct or All

toCColumn :: Column a -> Column ()   

Further infos:
  • solution complete, i.e., able to compute all solutions

toCValue :: Value a -> Value ()   

Further infos:
  • solution complete, i.e., able to compute all solutions

trCriteria :: Criteria -> String   

trOption :: [Option] -> String   

trCondition :: Condition -> String   

trConstraint :: Constraint -> String   

Further infos:
  • partially defined

trValue :: Value a -> String   

trColumn :: String -> Int -> String   

Further infos:
  • partially defined

trSpecifier :: Specifier -> String   

Further infos:
  • solution complete, i.e., able to compute all solutions