@@ -21,6 +21,10 @@ data Value = VInt Int
21 |VCol String
21 |VCol String
24+--Perhaps could extend this by adding
25+-- a dot operator to allow mapping
26+-- between table and column and
27+-- comparing different table columns.
25data Cond = Equals Value Value
29data Cond = Equals Value Value
26 |MkGT Value Value
30 |MkGT Value Value
@@ -29,7 +33,7 @@ data Cond = Equals Value Value
29 |MkLTE Value Value
33 |MkLTE Value Value
30 |MkNULL Value
34 |MkNULL Value
33data Clause = MkCond Cond
37data Clause = MkCond Cond
34 | AND Clause Clause
38 | AND Clause Clause
35 | OR Clause Clause
39 | OR Clause Clause
@@ -80,7 +84,8 @@ unwords = pack . unwords' . map unpack
81-----------------------------------------------------------
85-----------------------------------------------------------
82-- | This function replaces values with question mark
86-- | This function replaces values with question mark
83−-- following by an index number.
87+-- following by an index number. It then puts the value
88+-- replaced, in the list.
84-----------------------------------------------------------
89-----------------------------------------------------------
86valString : List (Maybe(Int, Value)) -> Value -> (String, List (Maybe(Int, Value)))
91valString : List (Maybe(Int, Value)) -> Value -> (String, List (Maybe(Int, Value)))
@@ -90,7 +95,8 @@ valString xs (VFloat x) = ("?" ++ show (cast(length xs)+1), xs ++ [Just (cast((l
90valString xs (VCol n) = (n, xs)
95valString xs (VCol n) = (n, xs)
92-----------------------------------------------------------
97-----------------------------------------------------------
93−-- | This function calls valString on a list of Values.
98+-- | This function calls valString on a list of Values
99+-- and separates the values by commas.
94-----------------------------------------------------------
100-----------------------------------------------------------
96listVal : List (Maybe(Int, Value)) -> List Value -> (String, List (Maybe(Int, Value)))
102listVal : List (Maybe(Int, Value)) -> List Value -> (String, List (Maybe(Int, Value)))
@@ -125,6 +131,7 @@ putBrackets str = "(" ++ str ++ ")"
126-----------------------------------------------------------
132-----------------------------------------------------------
127-- | Used to detect a complex type in a nested SQLite query
133-- | Used to detect a complex type in a nested SQLite query
134+-- This function is used for bracketing the nested queries.
128-----------------------------------------------------------
135-----------------------------------------------------------
129complexType : SQL -> Bool
136complexType : SQL -> Bool
130complexType (TBL tbl) = False
137complexType (TBL tbl) = False
@@ -144,7 +151,7 @@ listValType xs ((val, types, constr) :: vs) = let (str , newxs) = valString xs v
146-----------------------------------------------------------
153-----------------------------------------------------------
147−-- | Evaluates a condition after WHERE clause
154+-- | Evaluates a conditional WHERE clause
148-----------------------------------------------------------
155-----------------------------------------------------------
150evalCond : List (Maybe(Int, Value)) -> Cond -> (String, List (Maybe(Int, Value)))
157evalCond : List (Maybe(Int, Value)) -> Cond -> (String, List (Maybe(Int, Value)))
@@ -172,11 +179,15 @@ evalCond xs (MkNULL val) = let (restring , newxs ) = valString xs val in
172 (restring ++ " IS NULL " , newxs)
179 (restring ++ " IS NULL " , newxs)
174-----------------------------------------------------------
181-----------------------------------------------------------
175−-- | Evaluates queries
182+-- | Evaluates queries by calling the other functions
183+-- on each part of the query
176-----------------------------------------------------------
184-----------------------------------------------------------
177evalSQL : List (Maybe(Int, Value)) -> SQL -> ( String, List (Maybe(Int, Value)))
185evalSQL : List (Maybe(Int, Value)) -> SQL -> ( String, List (Maybe(Int, Value)))
178-----------------------------------------------------------
186-----------------------------------------------------------
179-- | Evaluates clauses
187-- | Evaluates clauses
188+-- Supports WHERE Clause
189+-- WHERE Clause And Another-Clause
190+-- WHERE Clause Or Another-Clause
180-----------------------------------------------------------
191-----------------------------------------------------------
181clauseString : List (Maybe(Int, Value)) -> Clause -> (String, List (Maybe(Int, Value)))
192clauseString : List (Maybe(Int, Value)) -> Clause -> (String, List (Maybe(Int, Value)))
@@ -206,7 +217,7 @@ condClauseStr xs (WHERE setcl1 setcl2) = let (condstr, newxs) = condClauseStr xs
206 ( condstr ++ " WHERE " ++ condstr', newxs')
217 ( condstr ++ " WHERE " ++ condstr', newxs')
208-- SELECT data from tbl1 where num > (SELECT num from tbl1 where num = 24)
219-- SELECT data from tbl1 where num > (SELECT num from tbl1 where num = 24)
209−-- evalSQL [] ((SELECT ALL) (TBL "tbl") (MkSQL ((SELECT ALL) (TBL "tbl") (MkCond (VCol ") ) ) )
220+-- evalSQL [] ((SELECT ALL)(TBL "tbl")(MkSQL ((SELECT ALL) (TBL "tbl")(MkCond (VCol "))))
211--clauseString xs (MkSQL sql) = (evalSQL xs sql)
222--clauseString xs (MkSQL sql) = (evalSQL xs sql)