honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
onetom 2020-03-18T06:15:33.029500Z

@ag i would probably just start with using sql/raw first for these more complicated cases. otherwise i started looking into the source code and the issue list to figure out whats possible and how

onetom 2020-03-18T06:30:16.034700Z

I just hit this inline-string issue myself after 1 hour of playing with honeysql: https://github.com/jkk/honeysql/issues/221 i was expecting it to know how to quote and escape strings, when i try to inline some string constants, like:

(-> {:select [:descr]
       :from   [:transaction]
       :where  [:like :descr (sql/inline "%\\\\\"%")]}
      (sql/format :quoting :mysql))
but what's tricky about it - i guess - is that the quoting and escaping rules between SQL dialects are different. however, there is already that :quoting option for sql/format so that would suggest that honeysql knows about this. things get even trickier, when we have to craft a string which is a pattern for the LIKE operator. in that case there are extra quoting rules applied on top of the default string escapes: https://dev.mysql.com/doc/refman/8.0/en/string-comparison-functions.html and u can even alter this quoting behaviour globally or on a per-session basis with: https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sqlmode_no_backslash_escapes on top of that add the extra rules of string literals combined with the ANSI_QUOTES sql_mode: https://dev.mysql.com/doc/refman/8.0/en/string-literals.html so it's a bit of a clusterfuck 🙂

seancorfield 2020-03-18T18:53:33.035700Z

Yeah, general support for turning arbitrary strings into valid SQL is nigh-impossible because of so many DB-specific corner cases.