@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
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 🙂Yeah, general support for turning arbitrary strings into valid SQL is nigh-impossible because of so many DB-specific corner cases.