Closed iarenaza closed 1 year ago
Ah, good catch! This is something I added in HoneySQ to deal with quoted entities that include the closing quote (which can be other characters in other dialects) but it hasn't been ported to next.jdbc
yet:
https://github.com/seancorfield/honeysql/blob/develop/src/honey/sql.cljc#L92-L95
And, to be clear, this can affect MySQL and SQL Server quoting too.
Describe the bug For a a number of reasons, our application needs to use end-user supplied values for column names in the database. In order to make sure the supplied names can be used as column names without problems, and that they don't collide with SQL key words, we need to use them as "delimited identifiers" (using ANSI SQL lingo).
We are using Postgresql, so the natural way of making sure everything works as expected in this case, is to use
next.jdbc.quoted/postgres
(directly, or indirectly throughnext.jdbc.quoted/schema
) as the value for:column-fn
option, to quote the column names.But it turns out that
ansi
quoting (which is what bothpostgres
andoracle
quoting functions use underneath) doesn't correctly deal with names that include double quotes inside them (yeah, we know, as I said, before, they users need to be able to choose those names, that is something that was imposed on us by $EXTERNAL_POWERS).According to the ANSI SQL 99 standard (the only one we could get our hands on without paying a lot of €€):
If our interpretation of the above is right, that means every single double quote mark in the original value (what the end-user provided) should produce a corresponding double quote mark in the quoted value.
But the
ansi
/posgres
/oracle
quoting functions just add the "surrounding" pair of quote marks, and don't deal with any quote marks that may be part of the value to quote.To Reproduce
The following piece of code, when evaluated in the REPL, should return
true
. But it returnsfalse
.Expected behavior
As stated before, the above piece of code should return
true
.project.clj/deps.edn
project.clj, trimmed to the relevant parts.
Environment (please complete the following information):