Hi Hilco,

Query.getSQL() will produce the SQL String that would be sent to the server
through JDBC. It works along with Query.getBindValues(), which is very
useful for instance if you want to use jOOQ only as a query builder, but
then execute the SQL with Spring or JPA's native queries, etc.

What you're looking for is any of these:

*Query.getSQL(ParamType.INLINED)*
This is probably what you were looking for

*DSLContext.renderInlined(QueryPart)*
Same as above, but a bit more generic

*Settings.statementType == StatementType.STATIC_STATEMENT*
work as if using not java.sql.PreparedStatement but static
java.sql.Statement, which doesn't support bind values. This will influence
the result of Query.getSQL()

*DSL.inline()*
enforce inlining of the bind variable locally only for this bind variable

*uery.toString()*
least reliable, as the behaviour may change in the future

Some of this is also mentioned in the Query.getSQL() Javadoc:
https://www.jooq.org/javadoc/latest/org/jooq/Query.html#getSQL--

Hope this helps,
Lukas


2017-02-17 5:41 GMT+01:00 Hilco Wijbenga <[email protected]>:

> On 16 February 2017 at 09:15, Hilco Wijbenga <[email protected]>
> wrote:
> > We are using jOOQ 3.6.4 because that is the most recent version that
> > does not require JDK 1.8.
> >
> > I ran into a strange problem yesterday when a jOOQ query did not work.
> > I boiled it down to the following:
> >
> > dslContext
> >                 .select(DSL.val(Integer.valueOf(1)))
> >                 .getQuery()
> >                 .getSQL()
> >
> > I would expect this to yield:
> >
> > SELECT 1 FROM DUAL
> >
> > but instead I get
> >
> > SELECT ? FROM DUAL
> >
> > which is the problem I'm having in the original query: each literal
> > value turns into a '?' instead of its actual value in the resulting
> > SQL query.
>
> As it turns out, this was *not* the reason the query did not work. It
> just took me by surprise and pointed me in the wrong direction.
>
> > What is the correct way to get a literal value in a select clause?
>
> So let me rephrase: why doesn't the printed SQL include the literal
> value? Clearly, the Param returned by DSL#val is merely a
> means-to-an-end and behind the scenes it gets a value. So would it not
> be possible to hide it completely when printing the resulting SQL?
>
> --
> 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.
>

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