Skip to content

Commit

Permalink
Handle empty SQL array values in DashboardDrawerRowMapper
Browse files Browse the repository at this point in the history
- Return an empty list if SQL array is null.
- Check for single empty value in SQL array and return an empty list.
- Convert valid SQL arrays to Java lists properly.
  • Loading branch information
TDeSain committed Nov 19, 2024
1 parent 116c767 commit cbcd311
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ public DashboardDrawer mapRow(ResultSet rs, int rowNum) throws SQLException {
}

private List<String> convertSqlArrayToList(Array sqlArray) throws SQLException {
if (sqlArray == null) {
if (sqlArray == null ) {
return List.of();
} else {
Object[] arrayContents = (Object[]) sqlArray.getArray();
// Check if the array contains a single empty value
if (arrayContents.length == 1 && "".equals(arrayContents[0])) {
return List.of();
} else {
return Arrays.asList((String[]) sqlArray.getArray());
}
}
// Convert SQL Array to Java Array, then to List
return Arrays.asList((String[]) sqlArray.getArray());
}
}

0 comments on commit cbcd311

Please sign in to comment.