jOOQ addConditions: in SQL question mark appears instead of the value

南楼画角 提交于 2019-12-06 03:45:48

问题


I would like to launch simple code:

SelectQuery query = dsl.select(field ("id"), field("title")).from("dict.models").getQuery();
if (modelId > 0) query.addConditions(field("model_id", SQLDataType.INTEGER).equal(modelId));

But infortunately in getSQL() I can only see:

select id, title from dict.models where model_id = ?

Where is a mistake?

Thanks.


回答1:


Query.getSQL() generates the SQL statement as it would be generated if you let jOOQ execute a PreparedStatement - with bind variables. The bind variables can be extracted in the right order via Query.getBindValues()

If you want to inline all bind values into the generated SQL, you have various options through the jOOQ API (all equivalent):

  • Using Query.getSQL(ParamType) with ParamType.INLINE
  • Using dsl.renderInlined(QueryPart)
  • Using StatementType.STATIC_STATEMENT in your Settings


来源:https://stackoverflow.com/questions/26809490/jooq-addconditions-in-sql-question-mark-appears-instead-of-the-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!