You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Carl Franklin Hall (Jira)" <ji...@apache.org> on 2022/12/06 03:33:00 UTC

[jira] [Resolved] (DBUTILS-144) RowProcessor.asMap is invalid for multiple computed columns with no aliases

     [ https://issues.apache.org/jira/browse/DBUTILS-144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Carl Franklin Hall resolved DBUTILS-144.
----------------------------------------
    Fix Version/s: 2.0
       Resolution: Fixed

Added extra check for null then use column index if still null.

> RowProcessor.asMap is invalid for multiple computed columns with no aliases
> ---------------------------------------------------------------------------
>
>                 Key: DBUTILS-144
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-144
>             Project: Commons DbUtils
>          Issue Type: Bug
>    Affects Versions: 1.7
>         Environment: JDK: OpenJDK 1.8.0_212
> JDBC Driver: JTDS 1.2.8.1
> Database: SQL Server 2017 (Docker image mcr.microsoft.com/mssql/server:2017-latest)
>  
>            Reporter: Robert Huffman
>            Assignee: Carl Franklin Hall
>            Priority: Minor
>             Fix For: 2.0
>
>
> At least one database driver (JDTS) returns an empty string for both ResultSet.getColumnName and ResultSet.getColumnLabel if it is not a table column and it has no alias. If there are more than one such column in a result set, then BasicRowProcessor.toMap will put all of them in the map using the empty string as key. This means only the last column added will be retained in the map.
> For example, this query will create map with a single entry (the result of the second case statement) using the key "":
> {{SELECT}}
> {{  CASE WHEN foo = 0 THEN '' ELSE 'FOO' END,}}
> {{  CASE WHEN bar = 0 THEN '' ELSE 'BAR' END}}
> FROM FooBar
> Presumably this is not an issue for most usages. However, for a tool that does something like run canned queries and output the result as JSON, this is a problem. I propose that if both the columnName and columnLabel are null or zero length, the column index (converted to a String) be used as the key.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)