Skip to content
Snippets Groups Projects
Commit 1e93aa5c authored by Cam Saül's avatar Cam Saül
Browse files

Fix handling dots in identifiers :honey_pot:

parent 109e9c3d
Branches
Tags
No related merge requests found
......@@ -183,13 +183,14 @@
"Convert HONEYSQL-FORM to a vector of SQL string and params, like you'd pass to JDBC."
[driver honeysql-form]
{:pre [(map? honeysql-form)]}
(try (binding [hformat/*subquery?* false]
(hsql/format honeysql-form
:quoting (quote-style driver)
:allow-dashed-names? true))
(catch Throwable e
(log/error (u/format-color 'red "Invalid HoneySQL form:\n%s" (u/pprint-to-str honeysql-form)))
(throw e))))
(let [[sql & args] (try (binding [hformat/*subquery?* false]
(hsql/format honeysql-form
:quoting (quote-style driver)
:allow-dashed-names? true))
(catch Throwable e
(log/error (u/format-color 'red "Invalid HoneySQL form:\n%s" (u/pprint-to-str honeysql-form)))
(throw e)))]
(into [(hx/unescape-dots sql)] args)))
(defn- qualify+escape ^clojure.lang.Keyword
([table]
......
......@@ -104,8 +104,9 @@
"ACCESS_MODE_DATA" "r"}))))
(defn- connection-details->spec [_ details]
(dbspec/h2 (if db/*allow-potentailly-unsafe-connections* details
(update details :db connection-string-set-safe-options))))
(dbspec/h2 (if db/*allow-potentailly-unsafe-connections*
details
(update details :db connection-string-set-safe-options))))
(defn- unix-timestamp->timestamp [_ expr seconds-or-milliseconds]
......
......@@ -43,7 +43,7 @@
"*Optional* Return a `CREATE TABLE` statement.")
(drop-table-if-exists-sql ^String [this, ^DatabaseDefinition dbdef, ^TableDefinition tabledef]
"*Optional* Return a `DROP TABLE IF EXISTS` statement.")
"*Optional* Return a `DROP TABLE IF EXISTS` statement.")
(add-fk-sql ^String [this, ^DatabaseDefinition dbdef, ^TableDefinition tabledef, ^FieldDefinition fielddef]
"*Optional* Return a `ALTER TABLE ADD CONSTRAINT FOREIGN KEY` statement.")
......@@ -85,7 +85,7 @@
"*Optional*. Load the rows for a specific table into a DB. `load-data-chunked` is the default implementation.")
(execute-sql! [driver ^Keyword context, ^DatabaseDefinition dbdef, ^String sql]
"Execute a string of raw SQL. Context is either `:server` or `:db`."))
"*Optional*. Execute a string of raw SQL. Context is either `:server` or `:db`."))
(defn- default-create-db-sql [driver {:keys [database-name]}]
......@@ -205,7 +205,7 @@
(defn- do-insert!
"Insert ROWS-OR-ROWS into TABLE-NAME for the DRIVER database defined by SPEC."
[driver spec table-name row-or-rows]
(let [prepare-key (comp keyword (partial prepare-identifier driver) name)
(let [prepare-key (comp keyword (partial prepare-identifier driver) hx/escape-dots name)
rows (if (sequential? row-or-rows)
row-or-rows
[row-or-rows])
......@@ -305,8 +305,8 @@
;; Add the SQL for creating each Table
(doseq [tabledef table-definitions]
(swap! statements conj (drop-table-if-exists-sql driver dbdef tabledef))
(swap! statements conj (create-table-sql driver dbdef tabledef)))
(swap! statements conj (drop-table-if-exists-sql driver dbdef tabledef)
(create-table-sql driver dbdef tabledef)))
;; Add the SQL for adding FK constraints
(doseq [{:keys [field-definitions], :as tabledef} table-definitions]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment