From e77814f7d117f9f5315d65a48a854e0128111bfc Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Mon, 30 Sep 2013 01:26:16 +1000 Subject: Fix a bug relating to table renaming When queries were being created their internal aliases were defaulting to the same as their external table names. This would normally have been fine, but in the case of a rename the simplistic implementation of table renames was leading to the external name being changed too. The solution: generate a (unique) random internal name for the table. That way the rename operation will only rename the unique internal name, not the constant external name (it would also, in theory, reduce the need for renames, but that optimisation probably isn't really worth doing for expected work loads). --- src/clojure_sql/dsl.clj | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/clojure_sql/dsl.clj b/src/clojure_sql/dsl.clj index 8264e24..015dfda 100644 --- a/src/clojure_sql/dsl.clj +++ b/src/clojure_sql/dsl.clj @@ -85,9 +85,10 @@ "Create a query on a database table. If `table` is itself a query it will be wrapped, otherwise `table` will be used as the table name." [table] - (q/map->Query (let [name (if (u/named? table) table "table")] - {:tables {name table} - :joins [name]}))) + (q/map->Query (let [table-name (if (u/named? table) (name table) "table") + table-keyword (keyword (gensym table-name))] + {:tables {table-keyword table} + :joins [table-keyword]}))) (defn ^:private into-map-duplicate-error [coll error-fn] (reduce (fn [acc [k v]] -- cgit v1.2.3