File tree 4 files changed +30
-5
lines changed
4 files changed +30
-5
lines changed Original file line number Diff line number Diff line change 74
74
75
75
; START: sql-query
76
76
(defn sql-query [q]
77
- (with-query-results res [q] (doall res)))
77
+ (with-query-results res q (doall res)))
78
78
; END: sql-query
79
79
80
80
(defn select-snippet [id]
81
81
(with-connection db
82
- (first (sql-query ( str " select * from snippets where id = " (coerce Integer id)) ))))
82
+ (first (sql-query [ " select * from snippets where id = ? " (coerce Integer id)] ))))
83
83
84
84
; START: last-created-id
85
85
(defn last-created-id
86
86
" Extract the last created id. Must be called in a transaction
87
87
that performed an insert. Expects HSQLDB return structure of
88
88
the form [{:@p0 id}]."
89
89
[]
90
- (first (vals (first (sql-query " CALL IDENTITY()" )))))
90
+ (first (vals (first (sql-query [ " CALL IDENTITY()" ] )))))
91
91
; END: last-created-id
92
92
93
93
; START: insert-snippet
Original file line number Diff line number Diff line change 9
9
:sequences :index-of-any :life-without-multi :multimethods.default
10
10
:macros :macros.chain-1 :macros.chain-2 :macros.chain-3 :macros.chain-4
11
11
:macros.chain-5 :lazy-index-of-any :macros.bench-1
12
- :concurrency :functional :snake ]))
12
+ :concurrency :functional :snake :snippet ]))
13
13
14
14
(def lancet-tests
15
15
(map #(symbol (str " lancet.test." (name %)))
Original file line number Diff line number Diff line change
1
+ (ns examples.test.snippet
2
+ (:use clojure.contrib.test-is clojure.contrib.sql examples.snippet))
3
+
4
+ (deftest insert-and-select-some-snippets
5
+ (let [stub-time (now )]
6
+ (binding [now (fn [] stub-time)]
7
+ (sample-snippets )
8
+ (is (= [{:id 0 , :body " (println :boo)" , :created_at stub-time}
9
+ {:id 1 , :body " (defn foo [] 1)" , :created_at stub-time}]
10
+ (select-snippets )))
11
+ (insert-snippet " boo!" )
12
+ (is (= {:id 2 , :body " boo!" , :created_at stub-time}
13
+ (select-snippet 2 ))))))
14
+
15
+ (deftest drop-and-create-snippets-table
16
+ (with-connection db (drop-snippets ))
17
+ (is (= " Table not found in statement [select * from snippets]"
18
+ (.getMessage (is (thrown? java.sql.SQLException (select-snippets ))))))
19
+ (ensure-snippets-table-exists )
20
+ (is (= nil (select-snippets ))))
21
+
22
+
23
+
24
+
25
+
Original file line number Diff line number Diff line change 1
- java -cp lib/clojure.jar:lib/clojure-contrib.jar:lib/ant.jar:lib/ant-launcher.jar:. clojure.lang.Script examples/test.clj
1
+ java -cp lib/clojure.jar:lib/clojure-contrib.jar:lib/hsqldb.jar:lib/ ant.jar:lib/ant-launcher.jar:. clojure.lang.Script examples/test.clj
You can’t perform that action at this time.
0 commit comments