FirebirdSQL / jaybird

JDBC driver for Firebird
https://firebirdsql.org/en/jdbc-driver/
GNU Lesser General Public License v2.1
91 stars 23 forks source link

Updatable server-side scrollable cursor reports wrong size when inserting a row through the result set before fetching #819

Closed mrotteveel closed 1 month ago

mrotteveel commented 1 month ago

While investigating #818, I noticed that the server-side scrollable cursor implementation reported the wrong size if I inserted a row through the result set immediately after execute (thus without fetching any rows), and the inserted row was included twice in the result set: once server-side, and once locally.

This happens because the cursor is not materialized server-side until the first fetch, and so the inserted row was materialized in the server-side cursor, and also stored in the local "inserted rows" list, and thus reported twice. We need to address this by forcing materialization of the cursor earlier, maybe immediately on creating the fetcher.

mrotteveel commented 1 month ago

To be frontported to Jaybird 6

mrotteveel commented 1 month ago

As bonus, the fix does away with some complexity in the fetcher. In the original implementation, I delayed knowing the server-side (and local) cursor size until absolutely necessary, but that involved some gnarly logic in places.

mrotteveel commented 1 month ago

I spoke too soon. There is actually a good reason for the convoluted logic. Avoiding the need to know the cursor size ahead of time conserves server resources by not materializing the entire result set.