>> done. but i did not test it :(. so be carefull
>
> Yes, I've noticed that there is a syntax error due to a missing
> closing parenthesis. After fixing that, the integration tests fail,
> though. I think, rownum is renamed for subsequent filtering at the
> wrong nesting level. I'll fix this too and commit shortly

As a matter of fact, the bind values were bound in the wrong order after
applying the pull request, now that the upper limit is bound to the
statement before the lower limit (as opposed to how it was before). This is
a bit tricky, as binding limits is externalised to org.jooq.impl.Limit,
whereas the SQL rendering for this complex kind of simulation has to be
taken care of in org.jooq.impl.AbstractSubSelect

The fixes contained in this commit here now run smoothly through all Oracle
integration tests:
https://github.com/jOOQ/jOOQ/commit/5c6638bd5cb6029d067bae68c1a107bb80f81cb6

Integration test Java Code:

Result<Record> result = create().select(nestedID, count())
   .from(create().selectFrom(TBook())
                 .orderBy(TBook_ID().desc())
                 .limit(1, 2).asTable("nested"))
   .groupBy(nestedID)
   .orderBy(nestedID)
   .fetch();

Rendered SQL:

select
 "nested"."AUTHOR_ID",
 count(*)
from (select * from (
       select limit_133537784.*, rownum as rownum_133537784
       from (
         select
           "TEST"."T_BOOK"."ID",
           "TEST"."T_BOOK"."AUTHOR_ID",
           "TEST"."T_BOOK"."CO_AUTHOR_ID",
           "TEST"."T_BOOK"."DETAILS_ID",
           "TEST"."T_BOOK"."TITLE",
           "TEST"."T_BOOK"."PUBLISHED_IN",
           "TEST"."T_BOOK"."LANGUAGE_ID",
           "TEST"."T_BOOK"."CONTENT_TEXT",
           "TEST"."T_BOOK"."CONTENT_PDF"
         from "TEST"."T_BOOK"
         order by "TEST"."T_BOOK"."ID" desc
       ) limit_133537784
       where rownum <= (1 + 2)
     )
     where rownum_133537784 > 1) "nested"
group by "nested"."AUTHOR_ID"
order by "nested"."AUTHOR_ID" asc

Note, I have also removed an unnecessary nesting level from the rendered
SELECT statement.

So #1020 is now fixed:
https://sourceforge.net/apps/trac/jooq/ticket/1020

Cheers
Lukas

Reply via email to