diff options
author | Carlo Zancanaro <carlo@clearboxsystems.com.au> | 2013-09-30 01:26:16 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@clearboxsystems.com.au> | 2013-09-30 01:26:16 +1000 |
commit | e77814f7d117f9f5315d65a48a854e0128111bfc (patch) | |
tree | e2304ac7f62b0ccbe01d9e33b0751813c04a9ed8 | |
parent | 65334fcffb989e01b348adef448d9a31a5065b0f (diff) |
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).
-rw-r--r-- | src/clojure_sql/dsl.clj | 7 |
1 files 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]] |