Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get row count and generated keys from batch #2060

Closed
doppelrittberger opened this issue Jun 30, 2022 · 4 comments
Closed

Get row count and generated keys from batch #2060

doppelrittberger opened this issue Jun 30, 2022 · 4 comments
Labels

Comments

@doppelrittberger
Copy link

doppelrittberger commented Jun 30, 2022

Hi,
I have the following use case:
I execute a lot of "UPDATE whatever SET (...) RETURNING id" using PreparedBatch. Unfortunately I need to access the rows by each batch statement individually (some UPDATE return no rows, some return multiple). What I need is a List<List>. When I do PreparedBatch.execute() I get the row counts per batch statement but cannot access the generated keys. Vice versa: if I use PreparedBatch.executeAndReturnGeneratedKeys() I cannot distinguish anymore which rows belong to which batch statement. If I would have access to both I could reconstruct the List<List>.

Is there a way to achieve this or is there another way using the ResultSet?
Thanks in advance 👍

@stevenschlansker
Copy link
Member

Hi @doppelrittberger, unfortunately I am not aware of a way to specifically do what you want. If you can figure out appropriate JDBC code to produce the results you like, we can try to figure out how to make it work through JDBI. But I have a suspicion that your request is probably too advanced for the relatively simple way JDBC handles generated key results.

doppelrittberger pushed a commit to doppelrittberger/jdbi that referenced this issue Jul 4, 2022
…d, added ResultIterable.lists() method, resolves jdbi#2060
@doppelrittberger
Copy link
Author

Hi,
I created #2061 which solves my use case. Please let me know if I need to change something. I created a test case as well to visualize the use case.
Best regards
Markus

hgschmie added a commit to hgschmie/jdbi that referenced this issue Jul 19, 2022
Add `executePreparedBatch` to supersede `executeAndReturnGeneratedKeys`,
which allows access to the modified row count after execution. Also add
a convenience method to the iterable that allows splitting up the list
of results into per-batch sets.

Addresses the problems described in jdbi#2060

Based on a proposal by @doppelrittberger (Markus Ritter)
@hgschmie
Copy link
Contributor

Hi @doppelrittberger. Thank you for the PR. I have iterated a bit on the code and I put up #2069. Please let me know it that solves your issues as well.

hgschmie added a commit that referenced this issue Jul 19, 2022
Add `executePreparedBatch` to supersede `executeAndReturnGeneratedKeys`,
which allows access to the modified row count after execution. Also add
a convenience method to the iterable that allows splitting up the list
of results into per-batch sets.

Addresses the problems described in #2060

Based on a proposal by @doppelrittberger (Markus Ritter)
@hgschmie
Copy link
Contributor

addressed by #2069

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants