Question about ExecuteListener's fetchEnd method data

32 views
Skip to first unread message

Fabio Cechinel Veronez

unread,
May 10, 2023, 10:14:52 AM5/10/23
to jOOQ User Group
Hi,

I have a question regarding ExecuteListener's fetchEnd hook method, more specifically about the data available in the ExecuteContext instance it receives.

According to `fetchEnd`'s Javadoc [1] the `ExecuteContext.query()` method returns

> The `Query` object, if a jOOQ query is being executed or `null` otherwise

However that appears not to be the case for some types of Queries. From what I could observer DML queries with RETURNING clauses won't be present in `ExecuteContext.query()`. I'm not sure whether it's the expected / designed behaviour or it's a bug.

For example, let say I have a (dummy) ExecuteListener configured as follow (in Kotlin):

```
configuration.setExecuteListener(
    ExecuteListener.onFetchEnd { ctx ->
        println("fetchEnd(query: ${ctx.query()})")
    }
)
```

A simple table structure as:

```
CREATE TABLE test (i INT);  
```

And a test code like:

```
val testTable: Table<*> = DSL.table(DSL.name("test"))  
val field = DSL.field("i", Int::class.java)
 
val rq1: ResultQuery<*> = ctx.selectFrom(testTable)  
val result1: Result<*> = rq1.fetch()  
assertEquals(listOf(1, 2, 3), result1.map { it.get(field) })  
 
val rq2: ResultQuery<*> = ctx.update(testTable).set(field, 3).returning(field)  
val result2: Result<*> = rq2.fetch()  
assertEquals(listOf(3, 3, 3), result2.map { it.get(field) })  
 
val rq3: ResultQuery<*> = ctx.resultQuery("UPDATE test SET i = 4 RETURNING *")  
val result3: Result<*> = rq3.fetch()  
assertEquals(listOf(4, 4, 4), result3.map { it.get(field) })
```

When I run the test the ExecuteContext instance will only contain the Query for the execution of `rq1` and `rq3` and not for `rq2`. It will then print

> fetchEnd(query: select *
> from "test")
> fetchEnd(query: null)
> fetchEnd(query: UPDATE test SET i = 4 RETURNING *)

It this difference on the behaviour of ExecuteListener's fetchEnd method expected or is it a bug?

Thanks in advance.

[1]: https://www.jooq.org/javadoc/3.17.12/org.jooq/org/jooq/ExecuteListener.html#fetchStart(org.jooq.ExecuteContext)

Lukas Eder

unread,
May 11, 2023, 3:13:53 AM5/11/23
to jooq...@googlegroups.com
Thanks for your message. That appears to be a bug. Can you please create an issue here: https://github.com/jOOQ/jOOQ/issues/new/choose

--
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 jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/fb60205f-1de2-4b06-9da8-14a51f34fe71n%40googlegroups.com.

Fabio Cechinel Veronez

unread,
May 12, 2023, 5:38:38 AM5/12/23
to jooq...@googlegroups.com
Thanks for the prompt response.
I have just created an issue for it, see
https://github.com/jOOQ/jOOQ/issues/15061.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/CAB4ELO7X%2BNt7%2BHNOmrtJhknJa_7sjS5CVrCx1RpMhHa8WmDs7g%40mail.gmail.com.



--
Fabio Cechinel Veronez
Reply all
Reply to author
Forward
0 new messages