-
Notifications
You must be signed in to change notification settings - Fork 356
Reestablish warning on duplicate column in query. #1825
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
Conversation
Object rsv = JdbcUtils.getResultSetValue(resultSet, i + 1); | ||
String columnName = md.getColumnLabel(i + 1); | ||
document.put(columnName, rsv instanceof Array a ? a.getArray() : rsv); | ||
Object old = document.put(columnName, rsv instanceof Array a ? a.getArray() : rsv); |
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.
I'm wondering why we're not using putIfAbsent
semantics. Obtaining a value from the ResultSet
typically uses the first occurrence of a column while we should be agnostic to the fact whether a column occurs multiple times in the result.
For reference, none of Spring JDBC's mappers care about duplicate columns, they just accept the fact that ResultSet
either returns different values when iterating over the column count or use the value by name lookup.
Furthermore, when an external query declares the same column names, why is it us to validate this concern?
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.
FWIW, the JDBC spec says when you have duplicate column names, the first one should be returned.
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 is it us to validate this concern?
Because we are nice people and we notice something is weird.
@@ -66,9 +71,13 @@ static RowDocument toRowDocument(ResultSet resultSet) throws SQLException { | |||
RowDocument document = new RowDocument(columnCount); | |||
|
|||
for (int i = 0; i < columnCount; i++) { | |||
|
|||
Object rsv = JdbcUtils.getResultSetValue(resultSet, i + 1); | |||
String columnName = md.getColumnLabel(i + 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.
Nit: We should use JdbcUtils.lookupColumnName(…)
here.
Made the changes requested by the review and merged. |
Closes #1680