Thanks for your fast reply. Custom ExecuteListener do exactly what I need without breaking standard JOOQ API usage.
Best regards, Lukas. Dne pátek 13. července 2018 10:34:38 UTC+2 Lukas Eder napsal(a): > > Hello, > > Your approach doesn't work well, because when you call the returning() > method on the DSL API, the resulting InsertQueryImpl will keep around some > flags related to that call. Calling context.resultQuery() accepting a plain > SQL statement does not have those flags. While this might still work in > PostgreSQL, whose INSERT .. RETURNING statement really behaves like a > ResultQuery, in most other databases this is not the case. jOOQ will use > Statement.getGeneratedKeys() behind the scenes and this is only possible if > those flags are set > > If you want to patch the generated SQL string, instead of extracting it, > patch it using an ExecuteListener prior to the execution. See: > > - https://www.jooq.org/javadoc/latest/org/jooq/ExecuteListener.html > - https://www.jooq.org/doc/latest/manual/sql-execution/execute-listeners > > I hope this helps, > Lukas > > Am Fr., 13. Juli 2018 um 10:03 Uhr schrieb <[email protected] <javascript:> > >: > >> TL;DL; >> How to get inserted keys (.getReturnedRecords()) from custom built insert >> query executed using context.resultQuery()? >> >> >> Hi, >> for selecting rows from db I use jooq query builder. In the end I export >> sql string using* query.getSQL(ParamType.INLINED). *Then I can do some >> regexp "fixing" on resulting SQL and pass it back to the >> *context.resultQuery()* and iterate over resultset. >> It works well for SELECT statements. However I need to INSERT data but I >> unfortunately still need to manually fix generated SQL. After passing fixed >> SQL into context.resultQuery() I cannot call >> .getResult().getReturnedRecords() because its result is not InsertQuery >> anymore. >> >> Casting seems not possible. >> >> Thanks. >> >> -- >> 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] <javascript:>. >> 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.
