Uploaded image for project: 'Commons DbUtils'
  1. Commons DbUtils
  2. DBUTILS-144

RowProcessor.asMap is invalid for multiple computed columns with no aliases

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.7
    • 2.0
    • None
    • 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)

       

    Description

      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.

      Attachments

        Activity

          People

            thecarlhall Carl Franklin Hall
            rthuffman Robert Huffman
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: