Address #134 by adding tests around bool/bit types
This commit is contained in:
parent
2f89d3d52b
commit
b210cbead7
2 changed files with 51 additions and 2 deletions
|
|
@ -124,6 +124,7 @@
|
|||
(.getPostgresDatabase ^EmbeddedPostgres @embedded-pg))
|
||||
(reset! test-datasource (jdbc/get-datasource db)))
|
||||
(let [fruit (if (mysql?) "fruit" "FRUIT") ; MySQL is case sensitive!
|
||||
btest (if (mysql?) "btest" "BTEST")
|
||||
auto-inc-pk
|
||||
(cond (or (derby?) (hsqldb?))
|
||||
(str "GENERATED ALWAYS AS IDENTITY"
|
||||
|
|
@ -146,6 +147,9 @@
|
|||
(try
|
||||
(do-commands con [(str "DROP TABLE " fruit)])
|
||||
(catch Exception _))
|
||||
(try
|
||||
(do-commands con [(str "DROP TABLE " btest)])
|
||||
(catch Exception _))
|
||||
(when (postgres?)
|
||||
(try
|
||||
(do-commands con ["DROP TABLE LANG_TEST"])
|
||||
|
|
@ -166,6 +170,24 @@ CREATE TABLE " fruit " (
|
|||
COST INT DEFAULT NULL,
|
||||
GRADE REAL DEFAULT NULL
|
||||
)")])
|
||||
(let [created (atom false)]
|
||||
;; MS SQL Server does not support bool/boolean:
|
||||
(doseq [btype ["BOOL" "BOOLEAN" "BIT"]]
|
||||
;; Derby does not support bit:
|
||||
(doseq [bitty ["BIT" "SMALLINT"]]
|
||||
(try
|
||||
(when-not @created
|
||||
(do-commands con [(str "
|
||||
CREATE TABLE " btest " (
|
||||
NAME VARCHAR(32),
|
||||
IS_IT " btype ",
|
||||
TWIDDLE " bitty "
|
||||
)")])
|
||||
(reset! created true))
|
||||
(catch Throwable _))))
|
||||
(when-not @created
|
||||
(println (:dbtype db) "failed btest creation")
|
||||
#_(throw (ex-info (str (:dbtype db) " has no boolean type?") {}))))
|
||||
(when (stored-proc?)
|
||||
(let [[begin end] (if (postgres?) ["$$" "$$"] ["BEGIN" "END"])]
|
||||
(try
|
||||
|
|
|
|||
|
|
@ -10,10 +10,11 @@
|
|||
[next.jdbc.test-fixtures
|
||||
:refer [with-test-db db ds column
|
||||
default-options stored-proc?
|
||||
derby? hsqldb? jtds? mssql? mysql? postgres?]]
|
||||
derby? hsqldb? jtds? mssql? mysql? postgres? sqlite?]]
|
||||
[next.jdbc.prepare :as prep]
|
||||
[next.jdbc.result-set :as rs]
|
||||
[next.jdbc.specs :as specs])
|
||||
[next.jdbc.specs :as specs]
|
||||
[next.jdbc.types :as types])
|
||||
(:import (java.sql ResultSet)))
|
||||
|
||||
(set! *warn-on-reflection* true)
|
||||
|
|
@ -312,6 +313,32 @@ VALUES ('Pear', 'green', 49, 47)
|
|||
(is (= 4 (count (jdbc/execute! con ["select * from fruit"]))))
|
||||
(is (= ac (.getAutoCommit con)))))))
|
||||
|
||||
(deftest bool-tests
|
||||
(doseq [[n b] [["zero" 0] ["one" 1] ["false" false] ["true" true]]
|
||||
:let [v-bit (if (number? b) b (if b 1 0))
|
||||
v-bool (if (number? b) (pos? b) b)]]
|
||||
(jdbc/execute-one!
|
||||
(ds)
|
||||
["insert into btest (name,is_it,twiddle) values (?,?,?)"
|
||||
n
|
||||
(if (postgres?)
|
||||
(types/as-boolean b)
|
||||
b) ; 0, 1, false, true are all acceptable
|
||||
(cond (hsqldb?)
|
||||
v-bool ; hsqldb requires a boolean here
|
||||
(postgres?)
|
||||
(types/as-other v-bit) ; really postgres??
|
||||
:else
|
||||
v-bit)]))
|
||||
(let [data (jdbc/execute! (ds) ["select * from btest"]
|
||||
(default-options))]
|
||||
(if (sqlite?)
|
||||
(is (every? number? (map (column :BTEST/IS_IT) data)))
|
||||
(is (every? boolean? (map (column :BTEST/IS_IT) data))))
|
||||
(if (or (sqlite?) (derby?))
|
||||
(is (every? number? (map (column :BTEST/TWIDDLE) data)))
|
||||
(is (every? boolean? (map (column :BTEST/TWIDDLE) data))))))
|
||||
|
||||
(deftest folding-test
|
||||
(jdbc/execute-one! (ds) ["delete from fruit"])
|
||||
(with-open [con (jdbc/get-connection (ds))
|
||||
|
|
|
|||
Loading…
Reference in a new issue