>
> Agree. I was going for something that would be fool-proof and do the
>> safe thing by default. We can revisit this in the future.
>>
>> Thanks for fixing this!
>
>
> We certainly should. I really wonder if there is any way through standard
> JDBC API to access the NO_BACKSLASH_ESCAPES property. I haven't found it in
> Connection.getClientInfo(), nor in INFORMATION_SCHEMA.SESSION_VARIABLES...
> I also don't find it in @@SESSION.sql_mode
>

The com.mysql.jdbc.ConnnectionImpl class contains this logic to expose the
noBackslashEscapes flag:

            if (this.serverVariables.containsKey("sql_mode")) {
                int sqlMode = 0;

                String sqlModeAsString =
this.serverVariables.get("sql_mode");
                try {
                    sqlMode = Integer.parseInt(sqlModeAsString);
                } catch (NumberFormatException nfe) {
                    // newer versions of the server has this as a string-y
list...
                    sqlMode = 0;

                    if (sqlModeAsString != null) {
                        if (sqlModeAsString.indexOf("ANSI_QUOTES") != -1) {
                            sqlMode |= 4;
                        }

                        if (sqlModeAsString.indexOf("NO_BACKSLASH_ESCAPES")
!= -1) {
                            this.noBackslashEscapes = true;
                        }
                    }
                }

                if ((sqlMode & 4) > 0) {
                    this.useAnsiQuotes = true;
                } else {
                    this.useAnsiQuotes = false;
                }
            }

It looks like the setting is only exposed if it is active. The variable can
be obtained from SHOW VARIABLES LIKE 'sql_mode', or via SELECT
@@SESSION.sql_mode
FROM DUAL. I suspect that if we support an AUTO mode, we would need to
check this flag prior to query execution (lazily, only the first time we
actually encounter an inlined string variable).

Another option would be to add another setting value called DEFAULT, which
means OFF for most databases and ON for MySQL / MariaDB. If the setting is
not specified, we'll actually use this DEFAULT as it aligns with MySQL's
own default. This would then be the sensible default for new users, to keep
them from running into this issue when they start using jOOQ.

What do you think?

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to