update tests for more recent sqlite

in particular, adding RETURNING * to insert, to get keys back
This commit is contained in:
Sean Corfield 2023-09-24 16:20:49 -07:00
parent c6b4587408
commit 04588e8ef2
3 changed files with 23 additions and 15 deletions

View file

@ -96,7 +96,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
(conj result (count (jdbc/execute! t ["select * from fruit"])))))))) (conj result (count (jdbc/execute! t ["select * from fruit"]))))))))
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"])))))) (is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"]))))))
(testing "return generated keys" (testing "return generated keys"
(when-not (mssql?) (when-not (or (mssql?) (sqlite?))
(let [results (let [results
(jdbc/with-transaction [t (ds) {:rollback-only true}] (jdbc/with-transaction [t (ds) {:rollback-only true}]
(with-open [ps (jdbc/prepare t [" (with-open [ps (jdbc/prepare t ["

View file

@ -97,13 +97,15 @@
(mssql?) :GENERATED_KEYS (mssql?) :GENERATED_KEYS
(mysql?) :GENERATED_KEY (mysql?) :GENERATED_KEY
(postgres?) :fruit/id (postgres?) :fruit/id
(sqlite?) (keyword "last_insert_rowid()")
:else :FRUIT/ID)] :else :FRUIT/ID)]
(testing "single insert/delete" (testing "single insert/delete"
(is (== 5 (new-key (sql/insert! (ds) :fruit (is (== 5 (new-key (sql/insert! (ds) :fruit
{:name (as-varchar "Kiwi") {:name (as-varchar "Kiwi")
:appearance "green & fuzzy" :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 (= 5 (count (sql/query (ds) ["select * from fruit"]))))
(is (= {:next.jdbc/update-count 1} (is (= {:next.jdbc/update-count 1}
(sql/delete! (ds) :fruit {:id 5}))) (sql/delete! (ds) :fruit {:id 5})))
@ -113,8 +115,6 @@
[nil] ; WTF Apache Derby? [nil] ; WTF Apache Derby?
(mssql?) (mssql?)
[8M] [8M]
(sqlite?)
[8]
(maria?) (maria?)
[6] [6]
:else :else
@ -124,7 +124,10 @@
[:name :appearance :cost :grade] [:name :appearance :cost :grade]
[["Kiwi" "green & fuzzy" 100 99.9] [["Kiwi" "green & fuzzy" 100 99.9]
["Grape" "black" 10 50] ["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 (= 7 (count (sql/query (ds) ["select * from fruit"]))))
(is (= {:next.jdbc/update-count 1} (is (= {:next.jdbc/update-count 1}
(sql/delete! (ds) :fruit {:id 6}))) (sql/delete! (ds) :fruit {:id 6})))
@ -137,8 +140,6 @@
[nil] ; WTF Apache Derby? [nil] ; WTF Apache Derby?
(mssql?) (mssql?)
[11M] [11M]
(sqlite?)
[11]
(maria?) (maria?)
[9] [9]
:else :else
@ -148,7 +149,10 @@
'(:name :appearance :cost :grade) '(:name :appearance :cost :grade)
'(("Kiwi" "green & fuzzy" 100 99.9) '(("Kiwi" "green & fuzzy" 100 99.9)
("Grape" "black" 10 50) ("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 (= 7 (count (sql/query (ds) ["select * from fruit"]))))
(is (= {:next.jdbc/update-count 1} (is (= {:next.jdbc/update-count 1}
(sql/delete! (ds) :fruit {:id 9}))) (sql/delete! (ds) :fruit {:id 9})))
@ -161,8 +165,6 @@
[nil] ; WTF Apache Derby? [nil] ; WTF Apache Derby?
(mssql?) (mssql?)
[14M] [14M]
(sqlite?)
[14]
(maria?) (maria?)
[12] [12]
:else :else
@ -180,7 +182,10 @@
{:name "Lemon" {:name "Lemon"
:appearance "yellow" :appearance "yellow"
:cost 20 :cost 20
:grade 9.9}])))) :grade 9.9}]
{:suffix
(when (sqlite?)
"RETURNING *")}))))
(is (= 7 (count (sql/query (ds) ["select * from fruit"])))) (is (= 7 (count (sql/query (ds) ["select * from fruit"]))))
(is (= {:next.jdbc/update-count 1} (is (= {:next.jdbc/update-count 1}
(sql/delete! (ds) :fruit {:id 12}))) (sql/delete! (ds) :fruit {:id 12})))
@ -191,7 +196,10 @@
(testing "empty insert-multi!" ; per #44 (testing "empty insert-multi!" ; per #44
(is (= [] (sql/insert-multi! (ds) :fruit (is (= [] (sql/insert-multi! (ds) :fruit
[:name :appearance :cost :grade] [:name :appearance :cost :grade]
[])))))) []
{:suffix
(when (sqlite?)
"RETURNING *")}))))))
(deftest no-empty-example-maps (deftest no-empty-example-maps
(is (thrown? clojure.lang.ExceptionInfo (is (thrown? clojure.lang.ExceptionInfo

View file

@ -619,7 +619,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
(conj result (count (jdbc/execute! t ["select * from fruit"])))))))) (conj result (count (jdbc/execute! t ["select * from fruit"]))))))))
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"])))))) (is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"]))))))
(testing "return generated keys" (testing "return generated keys"
(when-not (mssql?) (when-not (or (mssql?) (sqlite?))
(let [results (let [results
(jdbc/with-transaction [t (ds) {:rollback-only true}] (jdbc/with-transaction [t (ds) {:rollback-only true}]
(with-open [ps (jdbc/prepare t [" (with-open [ps (jdbc/prepare t ["
@ -763,7 +763,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
(jdbc/execute-one! (ds) ["delete from fruit where id > 4"]))))) (jdbc/execute-one! (ds) ["delete from fruit where id > 4"])))))
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"])))))) (is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"]))))))
(testing "return generated keys" (testing "return generated keys"
(when-not (mssql?) (when-not (or (mssql?) (sqlite?))
(let [results (let [results
(try (try
(let [result (jdbc/execute-batch! (ds) (let [result (jdbc/execute-batch! (ds)