on master help sign in
latest version
fed637dmelissam
contribs/lib/SQLite3/._sqlexpr.idr

Binary file not shown.

contribs/lib/SQLite3/._sqlite3.idr

Binary file not shown.

contribs/lib/SQLite3/sqlexpr.idr+3−1
@@ -221,7 +221,9 @@ condClauseStr xs (WHERE setcl1 setcl2) = let (condstr, newxs) = condClauseStr xs
221-- NTBF
221-- NTBF
222--clauseString xs (MkSQL sql) = (evalSQL xs sql)
222--clauseString xs (MkSQL sql) = (evalSQL xs sql)
223
223
224−-- Separate list of tables
224+-- Separate list of tables
225+-- For complex type, return list returned by evalSQL
226+-- And add brackets
225evalSQL xs (TBL tbl) = ((unwords (intersperse "," ( tbl))), xs)
227evalSQL xs (TBL tbl) = ((unwords (intersperse "," ( tbl))), xs)
226evalSQL xs (SELECT vars sql' c) = let (sqlstring, newxs) = evalSQL xs sql' in
228evalSQL xs (SELECT vars sql' c) = let (sqlstring, newxs) = evalSQL xs sql' in
227 let (csstring, newxs') = clauseString newxs c in
229 let (csstring, newxs') = clauseString newxs c in
contribs/lib/SQLite3/sqlite3.tex+15−7
@@ -11,14 +11,18 @@
11 \begin{document}
11 \begin{document}
12 \section{Introduction}
12 \section{Introduction}
13\label{Introduction}
13\label{Introduction}
14−This document provides overview on how the library for SQLite works. The code base is written on top of the
14+This document provides overview on how the Idris library for SQLite3 works. The code base is written on top of the
15SQLite3 C/C++ Interface.
15SQLite3 C/C++ Interface.
16This library supports some features of the low-level library, implemented in a higher level basis.
16This library supports some features of the low-level library, implemented in a higher level basis.
17−The library allows making use of data types as queries. The aim of this library is to avoid
17+The library allows making use of queries as data types. The aim of this library is to avoid
18SQL injections which are the most common security issues.
18SQL injections which are the most common security issues.
19To avoid this we have defined a datatype which describes queries.
19To avoid this we have defined a datatype which describes queries.
20The queries are written using these data types and parsed as quoted string
20The queries are written using these data types and parsed as quoted string
21−while replacing values with indexed question mark to be binded with the statement.
21+while replacing values with \emph{indexed question mark} to be binded with the prepared statement.
22+This prevents the user from preparing the queries inappropriately by not allowing to pass
23+any types of values directly to the prepare function. However this is a design choice, the library
24+does not prevent the user from passing a String directly to the prepare function.
25+
22\section{Using the library}
26\section{Using the library}
23\label{Using the library}
27\label{Using the library}
24Simple examples have been provided in the \emph{testunit.idr} file.
28Simple examples have been provided in the \emph{testunit.idr} file.
@@ -47,7 +51,7 @@ filling up the list with the received values. For instance the following is a va
47let sql = evalSQL [ ] ((SELECT ALL)(TBL ["tbl1"]) (MkCond (MkNULL (VCol "data"))))
51let sql = evalSQL [ ] ((SELECT ALL)(TBL ["tbl1"]) (MkCond (MkNULL (VCol "data"))))
48\newline
52\newline
49\newline{This will be parsed as :}
53\newline{This will be parsed as :}
50−\\“SELECT * FROM tbl1 WHERE data IS NULL “
54+\b{“SELECT * FROM tbl1 WHERE data IS NULL “}
51
55
52The evaluator returns a string and a list of indexed values.
56The evaluator returns a string and a list of indexed values.
53The string part of the query could be parsed to prepare.
57The string part of the query could be parsed to prepare.
@@ -56,7 +60,8 @@ storing them in the list given to it as an argument.
56For example:
60For example:
57
61
58
62
59−evalSQL [ ] (SELECT (Cols ["data"]) (SELECT (Cols["num","data"]) (TBL ["tbl1"])(MkCond(Equals(VCol "num")(VInt 2))))Empty))
63+evalSQL [ ] (SELECT (Cols ["data"]) (SELECT (Cols["num","data"]) (TBL ["tbl1"])
64+\newline (MkCond(Equals(VCol "num")(VInt 2))))Empty))
60
65
61is passed to prepare as :
66is passed to prepare as :
62
67
@@ -137,8 +142,8 @@ The library includes some wrapper functions such as get\_table
137and exec\_db. Using these functions mixed with prepare, step or finalize
142and exec\_db. Using these functions mixed with prepare, step or finalize
138inappropriately could cause segmentation faults.
143inappropriately could cause segmentation faults.
139Perhaps these functions could be removed from the library if no longer required in the future
144Perhaps these functions could be removed from the library if no longer required in the future
140−since the main purpose of this library is to make use of data types, or perhaps
145+since the main purpose of this library is to make use of data types.
141−these functionalities could be implemented internally without calling
146+However these functionalities could be implemented internally without calling
142the C Interface wrapper functions.
147the C Interface wrapper functions.
143
148
144\section{Further improving the library}
149\section{Further improving the library}
@@ -146,4 +151,7 @@ the C Interface wrapper functions.
146There are many features that could be added to this library. These include adding more useful SQL Commands,
151There are many features that could be added to this library. These include adding more useful SQL Commands,
147extending the SQL datatype to support more complex queries and possibly improving \emph{evalSQL}
152extending the SQL datatype to support more complex queries and possibly improving \emph{evalSQL}
148for a faster performance.
153for a faster performance.
154+Another useful thing to implement is the dot operator(.) which is the member access operator to yield
155+the value of a field in a table. This enables comparing values in different tables and constructing
156+more complex queries.
149\end{document}
157\end{document}