From 04588e8ef2a7ad895543ca2575bc6dcedf25dec8 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sun, 24 Sep 2023 16:20:49 -0700 Subject: [PATCH] update tests for more recent sqlite in particular, adding RETURNING * to insert, to get keys back --- test/next/jdbc/prepare_test.clj | 2 +- test/next/jdbc/sql_test.clj | 32 ++++++++++++++++++++------------ test/next/jdbc_test.clj | 4 ++-- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/test/next/jdbc/prepare_test.clj b/test/next/jdbc/prepare_test.clj index 4cf67ae..d0f1c86 100644 --- a/test/next/jdbc/prepare_test.clj +++ b/test/next/jdbc/prepare_test.clj @@ -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 [" diff --git a/test/next/jdbc/sql_test.clj b/test/next/jdbc/sql_test.clj index 80c4ba7..ec4e687 100644 --- a/test/next/jdbc/sql_test.clj +++ b/test/next/jdbc/sql_test.clj @@ -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}))) @@ -113,8 +115,6 @@ [nil] ; WTF Apache Derby? (mssql?) [8M] - (sqlite?) - [8] (maria?) [6] :else @@ -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}))) @@ -137,8 +140,6 @@ [nil] ; WTF Apache Derby? (mssql?) [11M] - (sqlite?) - [11] (maria?) [9] :else @@ -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}))) @@ -161,8 +165,6 @@ [nil] ; WTF Apache Derby? (mssql?) [14M] - (sqlite?) - [14] (maria?) [12] :else @@ -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}))) @@ -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 diff --git a/test/next/jdbc_test.clj b/test/next/jdbc_test.clj index aa07adf..1b895ab 100644 --- a/test/next/jdbc_test.clj +++ b/test/next/jdbc_test.clj @@ -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 [" @@ -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)