diff --git a/test/next/jdbc/result_set_test.clj b/test/next/jdbc/result_set_test.clj index 1fc106f..ea9b803 100644 --- a/test/next/jdbc/result_set_test.clj +++ b/test/next/jdbc/result_set_test.clj @@ -168,7 +168,7 @@ (is (= "Peach" ((column :FRUIT/name) row))))) (testing "custom row builder 2" (let [row (p/-execute-one (ds) - ["select fruit.*, id + 100 as newid from fruit where id = ?" 3] + [(str "select fruit.*, " (index) " + 100 as newid from fruit where " (index) " = ?") 3] (assoc (default-options) :builder-fn rs/as-modified-maps :label-fn str/lower-case @@ -236,7 +236,7 @@ (testing "row-numbers on bare abstraction" (is (= [1 2 3] (into [] (map rs/row-number) - (p/-execute (ds) ["select * from fruit where id < ?" 4] + (p/-execute (ds) [(str "select * from fruit where " (index) " < ?") 4] ;; we do not need a real builder here... (cond-> {:builder-fn (constantly nil)} (derby?) @@ -247,7 +247,7 @@ (is (= [1 2 3] (into [] (comp (map #(rs/datafiable-row % (ds) {})) (map rs/row-number)) - (p/-execute (ds) ["select * from fruit where id < ?" 4] + (p/-execute (ds) [(str "select * from fruit where " (index) " < ?") 4] ;; ...but datafiable-row requires a real builder (cond-> {:builder-fn rs/as-arrays} (derby?) @@ -257,7 +257,7 @@ (deftest test-column-names (testing "column-names on bare abstraction" - (is (= #{"id" "appearance" "grade" "cost" "name"} + (is (= #{(index) "appearance" "grade" "cost" "name"} (reduce (fn [_ row] (-> row (->> (rs/column-names) @@ -265,11 +265,11 @@ (set) (reduced)))) nil - (p/-execute (ds) ["select * from fruit where id < ?" 4] + (p/-execute (ds) [(str "select * from fruit where " (index) " < ?") 4] ;; column-names require a real builder {:builder-fn rs/as-arrays}))))) (testing "column-names on realized row" - (is (= #{"id" "appearance" "grade" "cost" "name"} + (is (= #{(index) "appearance" "grade" "cost" "name"} (reduce (fn [_ row] (-> row (rs/datafiable-row (ds) {}) @@ -278,7 +278,7 @@ (set) (reduced)))) nil - (p/-execute (ds) ["select * from fruit where id < ?" 4] + (p/-execute (ds) [(str "select * from fruit where " (index) " < ?") 4] {:builder-fn rs/as-arrays})))))) (deftest test-over-partition-all @@ -306,7 +306,7 @@ (p/-execute (ds) [(str "select * from fruit where " (index) " = ?") 1] {:builder-fn (constantly nil)})))) (is (= [[2 [:name "Banana"]]] - (into [] (map (juxt #(get % "id") ; get by string key works + (into [] (map (juxt #(get % (index)) ; get by string key works #(find % :name))) ; get MapEntry works (p/-execute (ds) [(str "select * from fruit where " (index) " = ?") 2] {:builder-fn (constantly nil)})))) @@ -417,7 +417,7 @@ (defn fruit-builder [^ResultSet rs ^ResultSetMetaData rsmeta] (reify rs/RowBuilder - (->row [_] (->Fruit (.getObject rs "id") + (->row [_] (->Fruit (.getObject rs ^String (index)) (.getObject rs "name") (.getObject rs "appearance") (.getObject rs "cost") @@ -497,10 +497,10 @@ CREATE TABLE CLOBBER ( (testing "get n on bare abstraction over arrays" (is (= [1 2 3] (into [] (map #(get % 0)) - (p/-execute (ds) ["select id from fruit where id < ?" 4] + (p/-execute (ds) [(str "select " (index) " from fruit where " (index) " < ?") 4] {:builder-fn rs/as-arrays}))))) (testing "nth on bare abstraction over arrays" (is (= [1 2 3] (into [] (map #(nth % 0)) - (p/-execute (ds) ["select id from fruit where id < ?" 4] + (p/-execute (ds) [(str "select " (index) " from fruit where " (index) " < ?") 4] {:builder-fn rs/as-arrays})))))) diff --git a/test/next/jdbc/sql_test.clj b/test/next/jdbc/sql_test.clj index 9e9190a..78b4ef3 100644 --- a/test/next/jdbc/sql_test.clj +++ b/test/next/jdbc/sql_test.clj @@ -89,17 +89,22 @@ (is (map? row)) (is (= 2 ((column :FRUIT/ID) row)))))) +(defn- update-count [n] + (if (xtdb?) + {:next.jdbc/update-count 0} + {:next.jdbc/update-count n})) + (deftest test-update! (let [ds-opts (jdbc/with-options (ds) (default-options))] (try - (is (= {:next.jdbc/update-count 1} + (is (= (update-count 1) (sql/update! ds-opts :fruit {:appearance "brown"} {(col-kw :id) 2}))) (is (= "brown" ((column :FRUIT/APPEARANCE) (sql/get-by-id ds-opts :fruit 2 (col-kw :id) {})))) (finally (sql/update! ds-opts :fruit {:appearance "yellow"} {(col-kw :id) 2}))) (try - (is (= {:next.jdbc/update-count 1} + (is (= (update-count 1) (sql/update! ds-opts :fruit {:appearance "green"} ["name = ?" "Banana"]))) (is (= "green" ((column :FRUIT/APPEARANCE) @@ -120,19 +125,17 @@ (xtdb?) (constantly 5) :else :FRUIT/ID)] (testing "single insert/delete" - (is (== 5 (new-key (doto - (sql/insert! (ds) :fruit - (cond-> {:name (as-varchar "Kiwi") - :appearance "green & fuzzy" - :cost 100 :grade (as-real 99.9)} - (xtdb?) - (assoc :_id 5)) - {:suffix - (when (sqlite?) - "RETURNING *")}) - (println (ds)))))) + (is (== 5 (new-key (sql/insert! (ds) :fruit + (cond-> {:name (as-varchar "Kiwi") + :appearance "green & fuzzy" + :cost 100 :grade (as-real 99.9)} + (xtdb?) + (assoc :_id 5)) + {:suffix + (when (sqlite?) + "RETURNING *")})))) (is (= 5 (count (sql/query (ds) ["select * from fruit"])))) - (is (= {:next.jdbc/update-count 1} + (is (= (update-count 1) (sql/delete! (ds) :fruit {(col-kw :id) 5}))) (is (= 4 (count (sql/query (ds) ["select * from fruit"]))))) (testing "multiple insert/delete" @@ -159,10 +162,10 @@ (when (sqlite?) "RETURNING *")})))) (is (= 7 (count (sql/query (ds) ["select * from fruit"])))) - (is (= {:next.jdbc/update-count 1} + (is (= (update-count 1) (sql/delete! (ds) :fruit {(col-kw :id) 6}))) (is (= 6 (count (sql/query (ds) ["select * from fruit"])))) - (is (= {:next.jdbc/update-count 2} + (is (= (update-count 2) (sql/delete! (ds) :fruit [(str (index) " > ?") 4]))) (is (= 4 (count (sql/query (ds) ["select * from fruit"]))))) (testing "multiple insert/delete with sequential cols/rows" ; per #43 @@ -189,10 +192,10 @@ (when (sqlite?) "RETURNING *")})))) (is (= 7 (count (sql/query (ds) ["select * from fruit"])))) - (is (= {:next.jdbc/update-count 1} + (is (= (update-count 1) (sql/delete! (ds) :fruit {(col-kw :id) 9}))) (is (= 6 (count (sql/query (ds) ["select * from fruit"])))) - (is (= {:next.jdbc/update-count 2} + (is (= (update-count 2) (sql/delete! (ds) :fruit [(str (index) " > ?") 4]))) (is (= 4 (count (sql/query (ds) ["select * from fruit"]))))) (testing "multiple insert/delete with maps" @@ -226,10 +229,10 @@ (when (sqlite?) "RETURNING *")})))) (is (= 7 (count (sql/query (ds) ["select * from fruit"])))) - (is (= {:next.jdbc/update-count 1} + (is (= (update-count 1) (sql/delete! (ds) :fruit {(col-kw :id) 12}))) (is (= 6 (count (sql/query (ds) ["select * from fruit"])))) - (is (= {:next.jdbc/update-count 2} + (is (= (update-count 2) (sql/delete! (ds) :fruit [(str (index) " > ?") 10]))) (is (= 4 (count (sql/query (ds) ["select * from fruit"]))))) (testing "empty insert-multi!" ; per #44 and #264 diff --git a/test/next/jdbc_test.clj b/test/next/jdbc_test.clj index 2f24295..4e486e1 100644 --- a/test/next/jdbc_test.clj +++ b/test/next/jdbc_test.clj @@ -117,12 +117,8 @@ (is (= (column :FRUIT/ID) (ffirst rs))) ;; and all its corresponding values should be ints (is (every? int? (map first (rest rs)))) - (when (xtdb?) (println (first rs) - (.indexOf ^java.util.List (first rs) :name) - (.indexOf (first rs) :name))) - (let [n (or (.indexOf ^java.util.List (first rs) :name) 1)] - (is (try (every? string? (map #(nth % n) (rest rs))) - (catch Throwable _ (println (rest rs)))))))) + (let [n (max (.indexOf ^java.util.List (first rs) :name) 1)] + (is (every? string? (map #(nth % n) (rest rs))))))) (testing "execute! with adapter" (let [rs (jdbc/execute! ; test again, with adapter and lower columns ds-opts @@ -140,12 +136,8 @@ (is (= (col-kw :fruit/id) (ffirst rs))) ;; and all its corresponding values should be ints (is (every? int? (map first (rest rs)))) - (when (xtdb?) (println (first rs) - (.indexOf ^java.util.List (first rs) :name) - (.indexOf (first rs) :name))) - (let [n (or (.indexOf ^java.util.List (first rs) :name) 1)] - (is (try (every? string? (map #(nth % n) (rest rs))) - (catch Throwable _ (println (rest rs)))))))) + (let [n (max (.indexOf ^java.util.List (first rs) :name) 1)] + (is (every? string? (map #(nth % n) (rest rs))))))) (testing "execute! with unqualified" (let [rs (jdbc/execute! (ds) @@ -169,12 +161,8 @@ (is (= (column :ID) (ffirst rs))) ;; and all its corresponding values should be ints (is (every? int? (map first (rest rs)))) - (when (xtdb?) (println (first rs) - (.indexOf ^java.util.List (first rs) :name) - (.indexOf (first rs) :name))) - (let [n (or (.indexOf ^java.util.List (first rs) :name) 1)] - (is (try (every? string? (map #(nth % n) (rest rs))) - (catch Throwable _ (println (rest rs)))))))) + (let [n (max (.indexOf ^java.util.List (first rs) :name) 1)] + (is (every? string? (map #(nth % n) (rest rs))))))) (testing "execute! with :max-rows / :maxRows" (let [rs (jdbc/execute! ds-opts