Complete support for MariaDB #100
Adds tests and test dependencies, based on a new environment variable. Updates change log. Documents difference in generated key return between MySQL and MariaDB.
This commit is contained in:
parent
9a1380c632
commit
780c759541
7 changed files with 21 additions and 9 deletions
|
|
@ -6,7 +6,7 @@ Only accretive/fixative changes will be made from now on.
|
||||||
|
|
||||||
The following changes have been made to **master** since the 1.0.405 build:
|
The following changes have been made to **master** since the 1.0.405 build:
|
||||||
|
|
||||||
None.
|
* Address #100 by adding support for MariaDB (@green-coder). Set `NEXT_JDBC_TEST_MARIADB=true` as well as `NEXT_JDBC_TEST_MYSQL=true` in order to run tests against MariaDB.
|
||||||
|
|
||||||
## Stable Builds
|
## Stable Builds
|
||||||
|
|
||||||
|
|
|
||||||
1
deps.edn
1
deps.edn
|
|
@ -16,6 +16,7 @@
|
||||||
org.hsqldb/hsqldb {:mvn/version "2.5.0"}
|
org.hsqldb/hsqldb {:mvn/version "2.5.0"}
|
||||||
com.h2database/h2 {:mvn/version "1.4.199"}
|
com.h2database/h2 {:mvn/version "1.4.199"}
|
||||||
net.sourceforge.jtds/jtds {:mvn/version "1.3.1"}
|
net.sourceforge.jtds/jtds {:mvn/version "1.3.1"}
|
||||||
|
org.mariadb.jdbc/mariadb-java-client {:mvn/version "2.5.4"}
|
||||||
mysql/mysql-connector-java {:mvn/version "8.0.19"}
|
mysql/mysql-connector-java {:mvn/version "8.0.19"}
|
||||||
org.postgresql/postgresql {:mvn/version "42.2.10"}
|
org.postgresql/postgresql {:mvn/version "42.2.10"}
|
||||||
com.opentable.components/otj-pg-embedded {:mvn/version "0.13.3"}
|
com.opentable.components/otj-pg-embedded {:mvn/version "0.13.3"}
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,13 @@ Consult the [java.sql.Blob documentation](https://docs.oracle.com/javase/8/docs/
|
||||||
|
|
||||||
## MS SQL Server
|
## MS SQL Server
|
||||||
|
|
||||||
|
In MS SQL Server, the generated key from an insert comes back as `:GENERATED_KEYS`.
|
||||||
|
|
||||||
By default, you won't get table names as qualifiers with Microsoft's JDBC driver (you might with the jTDS drive -- I haven't tried that recently). See this [MSDN forum post about `.getTableName()`](https://social.msdn.microsoft.com/Forums/sqlserver/en-US/55e8cbb2-b11c-446e-93ab-dc30658caf99/resultsetmetadatagettablename-returns-instead-of-table-name) for details. According to one of the answers posted there, if you specify `:result-type` and `:concurrency` in the options for `execute!`, `execute-one!`, `plan`, or `prepare`, that will cause SQL Server to return table names for columns. `:result-type` needs to be `:scoll-sensitive` or `:scroll-insensitive` for this to work. `:concurrency` can be `:read-only` or `:updatable`.
|
By default, you won't get table names as qualifiers with Microsoft's JDBC driver (you might with the jTDS drive -- I haven't tried that recently). See this [MSDN forum post about `.getTableName()`](https://social.msdn.microsoft.com/Forums/sqlserver/en-US/55e8cbb2-b11c-446e-93ab-dc30658caf99/resultsetmetadatagettablename-returns-instead-of-table-name) for details. According to one of the answers posted there, if you specify `:result-type` and `:concurrency` in the options for `execute!`, `execute-one!`, `plan`, or `prepare`, that will cause SQL Server to return table names for columns. `:result-type` needs to be `:scoll-sensitive` or `:scroll-insensitive` for this to work. `:concurrency` can be `:read-only` or `:updatable`.
|
||||||
|
|
||||||
## MySQL
|
## MySQL & MariaDB
|
||||||
|
|
||||||
|
In MySQL, the generated key from an insert comes back as `:GENERATED_KEY`. In MariaDB, the generated key from an insert comes back as `:insert_id`.
|
||||||
|
|
||||||
MySQL generally stores tables as files so they are case-sensitive if your O/S is (Linux) or case-insensitive if your O/S is not (Mac, Windows) but the column names are generally case-insensitive. This can matter when if you use `next.jdbc.result-set/as-lower-maps` because that will lower-case the table names (as well as the column names) so if you are round-tripping based on the keys you get back, you may produce an incorrect table name in terms of case. You'll also need to be careful about `:table-fn`/`:column-fn` because of this.
|
MySQL generally stores tables as files so they are case-sensitive if your O/S is (Linux) or case-insensitive if your O/S is not (Mac, Windows) but the column names are generally case-insensitive. This can matter when if you use `next.jdbc.result-set/as-lower-maps` because that will lower-case the table names (as well as the column names) so if you are round-tripping based on the keys you get back, you may produce an incorrect table name in terms of case. You'll also need to be careful about `:table-fn`/`:column-fn` because of this.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,12 +78,12 @@
|
||||||
:port 1433}
|
:port 1433}
|
||||||
"jtds:sqlserver" {:classname "net.sourceforge.jtds.jdbc.Driver"
|
"jtds:sqlserver" {:classname "net.sourceforge.jtds.jdbc.Driver"
|
||||||
:port 1433}
|
:port 1433}
|
||||||
|
"mariadb" {:classname "org.mariadb.jdbc.Driver"
|
||||||
|
:port 3306}
|
||||||
"mssql" {:classname "com.microsoft.sqlserver.jdbc.SQLServerDriver"
|
"mssql" {:classname "com.microsoft.sqlserver.jdbc.SQLServerDriver"
|
||||||
:alias-for "sqlserver"
|
:alias-for "sqlserver"
|
||||||
:dbname-separator ";DATABASENAME="
|
:dbname-separator ";DATABASENAME="
|
||||||
:port 1433}
|
:port 1433}
|
||||||
"mariadb" {:classname "org.mariadb.jdbc.Driver"
|
|
||||||
:port 3306}
|
|
||||||
"mysql" {:classname ["com.mysql.cj.jdbc.Driver"
|
"mysql" {:classname ["com.mysql.cj.jdbc.Driver"
|
||||||
"com.mysql.jdbc.Driver"]
|
"com.mysql.jdbc.Driver"]
|
||||||
:port 3306}
|
:port 3306}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
[next.jdbc.sql :as sql]
|
[next.jdbc.sql :as sql]
|
||||||
[next.jdbc.test-fixtures
|
[next.jdbc.test-fixtures
|
||||||
:refer [with-test-db ds column default-options
|
:refer [with-test-db ds column default-options
|
||||||
derby? mssql? mysql? postgres? sqlite?]]))
|
derby? maria? mssql? mysql? postgres? sqlite?]]))
|
||||||
|
|
||||||
(set! *warn-on-reflection* true)
|
(set! *warn-on-reflection* true)
|
||||||
|
|
||||||
|
|
@ -68,6 +68,7 @@
|
||||||
(deftest test-insert-delete
|
(deftest test-insert-delete
|
||||||
(let [new-key (cond (derby?) :1
|
(let [new-key (cond (derby?) :1
|
||||||
(mssql?) :GENERATED_KEYS
|
(mssql?) :GENERATED_KEYS
|
||||||
|
(maria?) :insert_id
|
||||||
(mysql?) :GENERATED_KEY
|
(mysql?) :GENERATED_KEY
|
||||||
(postgres?) :fruit/id
|
(postgres?) :fruit/id
|
||||||
(sqlite?) (keyword "last_insert_rowid()")
|
(sqlite?) (keyword "last_insert_rowid()")
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,11 @@
|
||||||
(defonce embedded-pg (future (EmbeddedPostgres/start)))
|
(defonce embedded-pg (future (EmbeddedPostgres/start)))
|
||||||
|
|
||||||
(def ^:private test-mysql-map
|
(def ^:private test-mysql-map
|
||||||
{:dbtype "mysql" :dbname "clojure_test" :useSSL false
|
(merge (if (System/getenv "NEXT_JDBC_TEST_MARIADB")
|
||||||
:user "root" :password (System/getenv "MYSQL_ROOT_PASSWORD")})
|
{:dbtype "mariadb"}
|
||||||
|
{:dbtype "mysql" :disableMariaDbDriver true})
|
||||||
|
{:dbname "clojure_test" :useSSL false
|
||||||
|
:user "root" :password (System/getenv "MYSQL_ROOT_PASSWORD")}))
|
||||||
(def ^:private test-mysql
|
(def ^:private test-mysql
|
||||||
(when (System/getenv "NEXT_JDBC_TEST_MYSQL") test-mysql-map))
|
(when (System/getenv "NEXT_JDBC_TEST_MYSQL") test-mysql-map))
|
||||||
|
|
||||||
|
|
@ -47,9 +50,11 @@
|
||||||
|
|
||||||
(defn derby? [] (= "derby" (:dbtype @test-db-spec)))
|
(defn derby? [] (= "derby" (:dbtype @test-db-spec)))
|
||||||
|
|
||||||
|
(defn maria? [] (= "mariadb" (:dbtype @test-db-spec)))
|
||||||
|
|
||||||
(defn mssql? [] (= "mssql" (:dbtype @test-db-spec)))
|
(defn mssql? [] (= "mssql" (:dbtype @test-db-spec)))
|
||||||
|
|
||||||
(defn mysql? [] (= "mysql" (:dbtype @test-db-spec)))
|
(defn mysql? [] (#{"mariadb" "mysql"} (:dbtype @test-db-spec)))
|
||||||
|
|
||||||
(defn postgres? [] (= "embedded-postgres" (:dbtype @test-db-spec)))
|
(defn postgres? [] (= "embedded-postgres" (:dbtype @test-db-spec)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -297,7 +297,8 @@ VALUES ('Pear', 'green', 49, 47)
|
||||||
ds (jdbc/get-datasource (assoc etc :jdbcUrl url))]
|
ds (jdbc/get-datasource (assoc etc :jdbcUrl url))]
|
||||||
(cond (derby?) (is (= {:create true} etc))
|
(cond (derby?) (is (= {:create true} etc))
|
||||||
(mssql?) (is (= #{:user :password} (set (keys etc))))
|
(mssql?) (is (= #{:user :password} (set (keys etc))))
|
||||||
(mysql?) (is (= #{:user :password :useSSL} (set (keys etc))))
|
(mysql?) (is (= #{:user :password :useSSL}
|
||||||
|
(disj (set (keys etc)) :disableMariaDbDriver)))
|
||||||
:else (is (= {} etc)))
|
:else (is (= {} etc)))
|
||||||
(is (instance? javax.sql.DataSource ds))
|
(is (instance? javax.sql.DataSource ds))
|
||||||
(is (str/index-of (pr-str ds) (str "jdbc:"
|
(is (str/index-of (pr-str ds) (str "jdbc:"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue