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

Summary of exported operations:

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

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  Deterministic 

An empty criteria

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

int :: Int -> Value Int  Deterministic 

Constructor for a Value Val of type Int

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

float :: Float -> Value Float  Deterministic 

Constructor for a Value Val of type Float

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

char :: Char -> Value Char  Deterministic 

Constructor for a Value Val of type Char

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

string :: String -> Value String  Deterministic 

Constructor for a Value Val of type String

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

bool :: Bool -> Value Bool  Deterministic 

Constructor for a Value Val of type Bool

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

date :: ClockTime -> Value ClockTime  Deterministic 

Constructor for a Value Val of type ClockTime

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

idVal :: Int -> Value a  Deterministic 

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  Deterministic 

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  Deterministic 

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  Deterministic 

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  Deterministic 

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  Deterministic 

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  Deterministic 

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  Deterministic 

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  Deterministic 

Infix Equal

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

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

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  Deterministic 

Infix NotEqual

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

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

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  Deterministic 

Infix GreaterThan

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

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

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  Deterministic 

Infix LessThan

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

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

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  Deterministic 

Infix GreaterThanEqual

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

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

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  Deterministic 

Infix LessThanEqual

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

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

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  Deterministic 

Infix Like

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

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

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  Deterministic 

IsIn construnctor

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

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

Infix IsIn

ascOrder :: Value a -> Option  Deterministic 

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  Deterministic 

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  Deterministic 

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

groupByCol :: Value a -> GroupByTail -> GroupByTail  Deterministic 

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  Deterministic 

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

noHave :: GroupByTail  Deterministic 

Constructor for empty having-Clause

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

condition :: Constraint -> Condition  Deterministic 

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

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

having-clauses.

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

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

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

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

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

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

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

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

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  Deterministic 

Constructor for aggregation function max in having-clauses.

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

toCColumn :: Column a -> Column ()  Deterministic 

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

toCValue :: Value a -> Value ()  Deterministic 

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

trCriteria :: Criteria -> String  Non-deterministic 

trOption :: [Option] -> String  Non-deterministic 

trCondition :: Condition -> String  Non-deterministic 

trConstraint :: Constraint -> String  Non-deterministic 

Further infos:
  • partially defined

trValue :: Value a -> String  Non-deterministic 

trColumn :: String -> Int -> String  Deterministic 

Further infos:
  • partially defined

trSpecifier :: Specifier -> String  Deterministic 

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