Skip to content

Commit

Permalink
Fix JDBC-26 by adding SQLite 3 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
seancorfield committed Mar 1, 2012
1 parent cab6edd commit 5d0bacc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,3 +10,4 @@ derby.log
target
test-all.sh
settings.xml
/clojure_test_sqlite
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -46,6 +46,12 @@
<version>8.4-702.jdbc4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
Expand Down
11 changes: 6 additions & 5 deletions src/main/clojure/clojure/java/jdbc/internal.clj
Expand Up @@ -351,11 +351,12 @@
[sql & param-groups]
(with-open [^PreparedStatement stmt (prepare-statement* (connection*) sql)]
(if (empty? param-groups)
(.addBatch stmt)
(doseq [param-group param-groups]
(set-parameters stmt param-group)
(.addBatch stmt)))
(transaction* (fn [] (seq (.executeBatch stmt))))))
(transaction* (fn [] (vector (.executeUpdate stmt))))
(do
(doseq [param-group param-groups]
(set-parameters stmt param-group)
(.addBatch stmt))
(transaction* (fn [] (seq (.executeBatch stmt))))))))

(defn with-query-results*
"Executes a query, then evaluates func passing in a seq of the results as
Expand Down
9 changes: 8 additions & 1 deletion src/test/clojure/clojure/java/test_jdbc.clj
Expand Up @@ -69,6 +69,9 @@
(def hsqldb-db {:subprotocol "hsqldb"
:subname "clojure_test_hsqldb"})

(def sqlite-db {:subprotocol "sqlite"
:subname "clojure_test_sqlite"})

(def postgres-db {:subprotocol "postgresql"
:subname "clojure_test"
:user "clojure_test"
Expand Down Expand Up @@ -222,6 +225,8 @@
"sqlserver" (is (= '({:generated_keys nil} {:generated_keys nil}) r))
"jtds:sqlserver" (is (= '({:id nil} {:id nil}) r))
"hsqldb" (is (= '(1 1) r))
"sqlite" (is (= (list {(keyword "last_insert_rowid()") 1}
{(keyword "last_insert_rowid()") 2}) r))
"derby" (is (= '({:1 nil} {:1 nil}) r))))
(is (= 2 (sql/with-query-results res ["SELECT * FROM fruit"] (count res))))
(is (= "Pomegranate" (sql/with-query-results res ["SELECT * FROM fruit WHERE cost = ?" 585] (:name (first res))))))))
Expand Down Expand Up @@ -295,7 +300,9 @@
[:name :appearance]
["Grape" "yummy"]
["Pear" "bruised"]
["Apple" "strange" "whoops"]))
["Apple" "strange" "whoops"])
;; sqlite does not throw exception for too many items
(throw (java.sql.SQLException.)))
(catch java.sql.SQLException _
(is (= 0 (sql/with-query-results res ["SELECT * FROM fruit"] (count res))))))
(is (= 0 (sql/with-query-results res ["SELECT * FROM fruit"] (count res)))))))
Expand Down

0 comments on commit 5d0bacc

Please sign in to comment.