layerware/hugsql

Blank comment lines in SQL files mess up HugSQL parsing

timgilbert opened this issue · 3 comments

I've got these two lines in a SQL file. Note that the second function contains a single blank comment right before the WHERE clause:

-- :name without-blank-comment :? :1
SELECT COUNT(*)
FROM users u
WHERE u.id = 1

-- :name with-blank-comment :? :1
SELECT COUNT(*)
FROM users u
--
WHERE u.id = 1

When I run this file via Clojure code looking similar to:

(hugsql/def-db-fns "hugsql/user.sql")

(defn comment-test []
  (log/spy (with-blank-comment (db/get-db-spec) {}))
  (log/spy (without-blank-comment (db/get-db-spec) {})))

The first result returns 1 (as I expected) but the second row returns 10 (one per row in that table in the database I'm connecting to).

It appears that somewhere in the SQL parsing, having a line that is only a comment string is aborting the processing, so that the WHERE clause is ignored in the name with-blank-comment function.

I doubt this is relevant, but I'm connecting to a Postgres backend; I've got [com.layerware/hugsql "0.4.6"]and [org.clojure/java.jdbc "0.4.2"] in my lein deps :tree output.

Looks like a bug! Thanks for the report. I can confirm this is also an issue in version 0.4.7.

This should be in the next release later this week. Thanks for the report!

This is released in 0.4.8 (finally!). Thanks!