问题
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