Skip to content

Commit

Permalink
Merge pull request #318 from sabracrolleton/master
Browse files Browse the repository at this point in the history
Added more tests to s-sql
  • Loading branch information
sabracrolleton committed Dec 14, 2022
2 parents f381345 + 6f7577d commit 3fb0051
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
4 changes: 2 additions & 2 deletions doc/s-sql.org
Original file line number Diff line number Diff line change
Expand Up @@ -964,13 +964,13 @@ Beginning in Postmodern v. 1.33.7, you can use lists with :in.

IMPORTANT REGARDING PARAMETERIZED QUERIES: For Postmodern versions before 1.33.7, you cannot use a list in a parameterized statement. You have to convert the list to a vector and use :any* rather than :in. See [[file:s-sql.html#sql-op-any][S-SQL#sql-op-any]] for more details.
#+begin_src lisp
(pomo:query (:select 'name :from 'employee :where (:= 'id (:any* '$1)))
(query (:select 'name :from 'employee :where (:= 'id (:any* '$1)))
#(1 3) :column)
'("Jason" "Celia")
#+end_src
;; Beginning with Postmodern version 1.33.7 you can also use lists
#+begin_src lisp
(pomo:query (:select 'name :from 'employee :where (:= 'id (:any* '$1)))
(query (:select 'name :from 'employee :where (:= 'id (:any* '$1)))
'(1 3) :column)
'("Jason" "Celia")
#+end_src
Expand Down
55 changes: 54 additions & 1 deletion s-sql/tests/tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,60 @@ name."
(is (equal (s-sql::to-s-sql-string '("alpha" "beta" "ceta" "Tau"))
"(\"alpha\",\"beta\",\"ceta\",\"Tau\")"))
(is (equal (s-sql::to-s-sql-string '(1 2 3 4))
"(1,2,3,4)")))
"(1,2,3,4)"))
(is (equal (s-sql::to-s-sql-string #("alpha" "beta" "ceta" "Tau"))
"{\"alpha\",\"beta\",\"ceta\",\"Tau\"}"))
(build-employee-table)
(with-test-connection
(is (equal (query (:select 'name 'salary
:from 'employee
:where (:in 'name '("Jason" "Robert"))))
'(("Jason" 40420) ("Robert" 14420))))
(is (equal (let ((emp-ids '(1 2)))
(query (:select 'name
:from 'employee
:where (:in 'id emp-ids))))
'(("Jason") ("Robert"))))
(is (equal (let ((emp-ids '(1 2)))
(query (:order-by
(:select 'name
:from 'employee
:where (:not-in 'id emp-ids))
'name)))
'(("Alison") ("Celia") ("Chris") ("David") ("James") ("Linda") ("Mary"))))
(is (equal (let ((a "Jason"))
(query (:select 'name 'salary
:from 'employee
:where (:in 'name `(,a "Robert")))))
'(("Jason" 40420) ("Robert" 14420))))
(is (equal (query (:select 'name
:from 'employee
:where (:= 'id (:any* '$1)))
#(1 3) :column)
'("Jason" "Celia")))
(is (equal (query (:select 'name
:from 'employee
:where (:= 'id (:any* '$1)))
'(1 3) :column)
'("Jason" "Celia")))
(is (equal (let ((toy-query (vector 1 2)))
(query (:select 'name
:from 'employee
:where (:= 'id (:any* '$1)))
toy-query))
'(("Jason") ("Robert"))))
(is (equal (let ((toy-query (list 1 2)))
(query (:select 'name
:from 'employee
:where (:= 'id (:any* '$1)))
toy-query))
'(("Jason") ("Robert"))))
(is (equal (let ((toy-query '(1 2)))
(query (:select 'name
:from 'employee
:where (:= 'id (:any* '$1)))
toy-query))
'(("Jason") ("Robert"))))))

(test sql-escape-string
"Testing sql-escape-string. Escape string data so it can be used in a query."
Expand Down

0 comments on commit 3fb0051

Please sign in to comment.