Robert Huffman created DBUTILS-144:
--------------------------------------

             Summary: 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


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.3.4#803005)

Reply via email to