I recently updated a project's jooq version from 3.13.5 to 3.14.15. I've rerun jooq-codegen. I'm using MySQL 5.7.
When running one of my tests - it performs a DAOImpl.exists
. That call generates the following exception:
org.jooq.exception.DataAccessException: SQL [select `count`(*) from `users` where `users`.`id` = ?]; You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) from `users` where `users`.`id` = 1094' at line 1
at org.jooq_3.14.15.MYSQL.debug(Unknown Source)
at org.jooq.impl.Tools.translate(Tools.java:2903)
at org.jooq.impl.DefaultExecuteContext.sqlException(DefaultExecuteContext.java:757)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:389)
at org.jooq.impl.AbstractResultQuery.fetchLazy(AbstractResultQuery.java:453)
at org.jooq.impl.AbstractResultQuery.fetchLazy(AbstractResultQuery.java:422)
at org.jooq.impl.AbstractResultQuery.fetchLazyNonAutoClosing(AbstractResultQuery.java:436)
at org.jooq.impl.AbstractResultQuery.fetchOne(AbstractResultQuery.java:613)
at org.jooq.impl.AbstractResultQuery.fetchOne(AbstractResultQuery.java:565)
at org.jooq.impl.SelectImpl.fetchOne(SelectImpl.java:3034)
at org.jooq.impl.DAOImpl.existsById(DAOImpl.java:300)
at org.jooq.impl.DAOImpl.exists(DAOImpl.java:288)
The problem is that count
has backticks. It should be select count(*) from `users` where `users`.`id` = ?
Has anyone run into this before and know how to fix it? TIA
CodePudding user response:
You probably specified RenderQuotedNames.ALWAYS
and ran into this problem? https://github.com/jOOQ/jOOQ/issues/9931
The setting ALWAYS
is misleading. It really means literally always, though people probably read it as ALWAYSISH_I_E_ONLY_WHEN_IT_MAKES_SENSE
. Probably a naming design error, but what you want is EXPLICIT_DEFAULT_QUOTED
, see the documentation:
https://www.jooq.org/doc/latest/manual/sql-building/dsl-context/custom-settings/settings-name-style/
RenderQuotedNames
ALWAYS
: This will quote all identifiers.EXPLICIT_DEFAULT_QUOTED
: This will quote all identifiers, which are not explicitly unquoted usingDSL.unquotedName()
.EXPLICIT_DEFAULT_UNQUOTED
: This will not quote any identifiers, unless they are explicitly quoted usingDSL.quotedName()
.NEVER
: This will not quote any identifiers.
COUNT
in DSL.count()
is an explicitly unquoted name, and ALWAYS
will override that.