From e0cafbd4342a89eee395151c6b924ebd51c19f5d Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Fri, 3 Dec 2021 13:06:34 -0800 Subject: [PATCH] extend lint checks to several column lists --- CHANGELOG.md | 1 + doc/getting-started.md | 3 ++- src/honey/sql.cljc | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab02980..9a5b4c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * 2.1.next in progress * Fix #372 by merging `:select-distinct-on` differently. + * Add empty column list check for `SELECT` and several other clauses, when `:checking :basic` (or `:strict`) is provided. * Update `build-clj` to v0.6.0. * 2.1.829 -- 2021-11-27 diff --git a/doc/getting-started.md b/doc/getting-started.md index d972c6a..fb0eee9 100644 --- a/doc/getting-started.md +++ b/doc/getting-started.md @@ -364,7 +364,8 @@ was wrapped in `[:inline `..`]`: * everything else is just turned into a string (by calling `str`) and added to the SQL string. The `:checking` option defaults to `:none`. If `:checking :basic` is -specified, certain obvious errors -- such as `IN` with an empty collection -- +specified, certain obvious errors -- such as `IN` with an empty collection +or `SELECT` with an empty list of columns -- are treated as an error and an exception is thrown. If `:checking :strict` is specified, certain dubious constructs -- such as `IN` with a collection containing `NULL` values -- are also treated as an error and an exception is diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index d347387..14cfd1a 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -372,6 +372,10 @@ [(conj sql sql') (if params' (into params params') params)]) [[] []] (map #(format-selectable-dsl % {:as as}) xs))] + (when-not (= :none *checking*) + (when (empty? xs) + (throw (ex-info (str prefix " empty column list is illegal") + {:clause (into [prefix] xs)})))) (into [(str prefix " " (str/join ", " sqls))] params)) (let [[sql & params] (format-selectable-dsl xs {:as as})] (into [(str prefix " " sql)] params))))