Skip to content

Commit

Permalink
update tests for more recent sqlite
Browse files Browse the repository at this point in the history
in particular, adding RETURNING * to insert, to get keys back
  • Loading branch information
seancorfield committed Sep 24, 2023
1 parent c6b4587 commit 04588e8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion test/next/jdbc/prepare_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
(conj result (count (jdbc/execute! t ["select * from fruit"]))))))))
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"]))))))
(testing "return generated keys"
(when-not (mssql?)
(when-not (or (mssql?) (sqlite?))
(let [results
(jdbc/with-transaction [t (ds) {:rollback-only true}]
(with-open [ps (jdbc/prepare t ["
Expand Down
32 changes: 20 additions & 12 deletions test/next/jdbc/sql_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@
(mssql?) :GENERATED_KEYS
(mysql?) :GENERATED_KEY
(postgres?) :fruit/id
(sqlite?) (keyword "last_insert_rowid()")
:else :FRUIT/ID)]
(testing "single insert/delete"
(is (== 5 (new-key (sql/insert! (ds) :fruit
{:name (as-varchar "Kiwi")
:appearance "green & fuzzy"
:cost 100 :grade (as-real 99.9)}))))
:cost 100 :grade (as-real 99.9)}
{:suffix
(when (sqlite?)
"RETURNING *")}))))
(is (= 5 (count (sql/query (ds) ["select * from fruit"]))))
(is (= {:next.jdbc/update-count 1}
(sql/delete! (ds) :fruit {:id 5})))
Expand All @@ -113,8 +115,6 @@
[nil] ; WTF Apache Derby?
(mssql?)
[8M]
(sqlite?)
[8]
(maria?)
[6]
:else
Expand All @@ -124,7 +124,10 @@
[:name :appearance :cost :grade]
[["Kiwi" "green & fuzzy" 100 99.9]
["Grape" "black" 10 50]
["Lemon" "yellow" 20 9.9]]))))
["Lemon" "yellow" 20 9.9]]
{:suffix
(when (sqlite?)
"RETURNING *")}))))
(is (= 7 (count (sql/query (ds) ["select * from fruit"]))))
(is (= {:next.jdbc/update-count 1}
(sql/delete! (ds) :fruit {:id 6})))
Expand All @@ -137,8 +140,6 @@
[nil] ; WTF Apache Derby?
(mssql?)
[11M]
(sqlite?)
[11]
(maria?)
[9]
:else
Expand All @@ -148,7 +149,10 @@
'(:name :appearance :cost :grade)
'(("Kiwi" "green & fuzzy" 100 99.9)
("Grape" "black" 10 50)
("Lemon" "yellow" 20 9.9))))))
("Lemon" "yellow" 20 9.9))
{:suffix
(when (sqlite?)
"RETURNING *")}))))
(is (= 7 (count (sql/query (ds) ["select * from fruit"]))))
(is (= {:next.jdbc/update-count 1}
(sql/delete! (ds) :fruit {:id 9})))
Expand All @@ -161,8 +165,6 @@
[nil] ; WTF Apache Derby?
(mssql?)
[14M]
(sqlite?)
[14]
(maria?)
[12]
:else
Expand All @@ -180,7 +182,10 @@
{:name "Lemon"
:appearance "yellow"
:cost 20
:grade 9.9}]))))
:grade 9.9}]
{:suffix
(when (sqlite?)
"RETURNING *")}))))
(is (= 7 (count (sql/query (ds) ["select * from fruit"]))))
(is (= {:next.jdbc/update-count 1}
(sql/delete! (ds) :fruit {:id 12})))
Expand All @@ -191,7 +196,10 @@
(testing "empty insert-multi!" ; per #44
(is (= [] (sql/insert-multi! (ds) :fruit
[:name :appearance :cost :grade]
[]))))))
[]
{:suffix
(when (sqlite?)
"RETURNING *")}))))))

(deftest no-empty-example-maps
(is (thrown? clojure.lang.ExceptionInfo
Expand Down
4 changes: 2 additions & 2 deletions test/next/jdbc_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
(conj result (count (jdbc/execute! t ["select * from fruit"]))))))))
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"]))))))
(testing "return generated keys"
(when-not (mssql?)
(when-not (or (mssql?) (sqlite?))
(let [results
(jdbc/with-transaction [t (ds) {:rollback-only true}]
(with-open [ps (jdbc/prepare t ["
Expand Down Expand Up @@ -763,7 +763,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
(jdbc/execute-one! (ds) ["delete from fruit where id > 4"])))))
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"]))))))
(testing "return generated keys"
(when-not (mssql?)
(when-not (or (mssql?) (sqlite?))
(let [results
(try
(let [result (jdbc/execute-batch! (ds)
Expand Down

0 comments on commit 04588e8

Please sign in to comment.