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
Use generatedKeys to fetch sequence values on insertRow() #1743
Conversation
Signed-off-by: KJA <31474178+kimjand@users.noreply.github.com>
Signed-off-by: KJA <31474178+kimjand@users.noreply.github.com>
Seems legit. I'd like to see tests where more than just one column is generated |
Signed-off-by: KJA <31474178+kimjand@users.noreply.github.com>
So you would like to see some more tests with a composite primary key? |
Signed-off-by: KJA <31474178+kimjand@users.noreply.github.com>
Signed-off-by: KJA <31474178+kimjand@users.noreply.github.com>
Codecov Report
@@ Coverage Diff @@
## master #1743 +/- ##
============================================
+ Coverage 69.31% 69.46% +0.15%
- Complexity 4205 4217 +12
============================================
Files 187 187
Lines 17312 17325 +13
Branches 2882 2883 +1
============================================
+ Hits 11999 12034 +35
+ Misses 4018 4001 -17
+ Partials 1295 1290 -5 |
Signed-off-by: KJA <31474178+kimjand@users.noreply.github.com>
Do you have any other comments or objections against this change? |
Great PR! I would love for this to be merged |
How do we proceed from here? Or should I consider this change rejected? |
} else { | ||
try { | ||
rowBuffer.set(columnIndex, | ||
PGbytea.toPGString((byte[]) valueObject).getBytes("ISO-8859-1")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ISO-8859-1 ? The driver generally assumes UTF-8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While a valid question, I do not have the answer. I just pulled the loop out of this method, reducing the indentation level by one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm ok, for now leave it but can you add a new issue to review this later
pgjdbc/src/test/java/org/postgresql/test/jdbc2/UpdateableResultTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: KJA <31474178+kimjand@users.noreply.github.com>
* Use generatedKeys to fetch sequence values on insertRow().
All Submissions:
New Feature Submissions:
Changes to Existing Features:
Description
I am not sure if this should be considered a new feature or a bugfix to the Updatable ResultSet method insertRow().
After a a row is inserted, we do not know the value of any generated columns. So why not use an insert statement created with RETURN_GENERATED_KEYS to fill in the blanks?
What I did was look at the way primaryKeys is being build. So I concluded that aliasing is not allowed in the SQL text for the Updatable Statement. This means we can rely on the field PrimaryKey.name being present in the generatedKeys resultset.
So I changed updateRowBuffer to update the rowBuffer on insert, using the mapping provided by the primaryKeys list.
Any thoughts on this? Tests pass, but I might have missed something as this is my first attempt at a pull request.