Skip to content

Commit

Permalink
Adds support for qualifying columns with table.
Browse files Browse the repository at this point in the history
Adds support common in other ResultSet implemenatations for qualifying column names with table name to distinguish potentially duplicate column names in a join of two or more tables from one another. The expected format is {table_name}.{column_namne}, where column_name is the actuall designated column name and not the column label.
  • Loading branch information
attermann authored and jhoeller committed May 8, 2024
1 parent 2d942a6 commit cb48077
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,23 @@ public ResultSetWrappingSqlRowSet(ResultSet resultSet) throws InvalidResultSetAc
ResultSetMetaData rsmd = resultSet.getMetaData();
if (rsmd != null) {
int columnCount = rsmd.getColumnCount();
this.columnLabelMap = CollectionUtils.newHashMap(columnCount);
this.columnLabelMap = CollectionUtils.newHashMap(columnCount * 2);
for (int i = 1; i <= columnCount; i++) {
String key = rsmd.getColumnLabel(i);
// Make sure to preserve first matching column for any given name,
// as defined in ResultSet's type-level javadoc (lines 81 to 83).
if (!this.columnLabelMap.containsKey(key)) {
this.columnLabelMap.put(key, i);
}
// Also support column names prefixed with table name
// as in {table_name}.{column.name}.
String table = rsmd.getTableName(i);
if (table != null && !table.isEmpty()) {
key = table + "." + rsmd.getColumnName(i);
if (!this.columnLabelMap.containsKey(key)) {
this.columnLabelMap.put(key, i);
}
}
}
}
else {
Expand Down

0 comments on commit cb48077

Please sign in to comment.