From 284d0142b6601359fa155d2bcaf537845ca82b93 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sun, 2 Sep 2018 18:35:02 -0700 Subject: [PATCH] Fix #226 by adding assert --- CHANGES.md | 1 + src/honeysql/format.cljc | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 38eb612..afa192f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ * `#sql/inline nil` should produce `NULL`. Fix #221. (@seancorfield) * `#sql/inline :kw` should produce `"kw"`. Fix #224 via PR #225. (@vincent-dm) Note: this introduces a new protocol, `Inlinable`, which controls inline value rendering, and changes the behavior of `#sql/inline :foo/bar` to produce just `"bar"` (where it was probably invalid SQL before). +* Alias expressions `[:col :alias]` are now checked to have exactly two elements. Fix #226. ## 0.9.3 diff --git a/src/honeysql/format.cljc b/src/honeysql/format.cljc index f0ea451..c4a853d 100644 --- a/src/honeysql/format.cljc +++ b/src/honeysql/format.cljc @@ -349,14 +349,16 @@ (paren-wrap (comma-join (map to-sql x))) :else ;; alias - (str (to-sql (first x)) - ; Omit AS in FROM, JOIN, etc. - Oracle doesn't allow it - (if (= :select *clause*) - " AS " - " ") - (if (string? (second x)) - (quote-identifier (second x)) - (to-sql (second x)))))) + (do + (assert (= 2 (count x)) (str "Alias should have two parts" x)) + (str (to-sql (first x)) + ; Omit AS in FROM, JOIN, etc. - Oracle doesn't allow it + (if (= :select *clause*) + " AS " + " ") + (if (string? (second x)) + (quote-identifier (second x)) + (to-sql (second x))))))) (extend-protocol types/Inlinable #?(:clj clojure.lang.Keyword