jprante / jdbc-driver-csv

JDBC driver for CSV

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lowercase column names in where clause are not found if not in select clause

davidmichaelkarr opened this issue · comments

This took quite a while of stepping through the code to find.

One of my csv files has the following header:

NAME,CODE,SUBCODE,VALUE_EN,VALUE_ES,EXTERNAL_VALUE,ACTIVE,SORT_INDEX

The where clause used to query this is the following:
select distinct name, code, subcode, value_en, value_es, sort_index from onemap_display_enums where active = 'Y'

However, this will fail with the following:
Invalid column name: active

At this point in time, we're executing the following block of code:

for (Object usedColumn : this.usedColumns) {
    if (!allReaderColumns.contains(usedColumn)) {
        throw new SQLException(CsvResources.getString("invalidColumnName") + ": " + usedColumn);
    }
}

This is line 415 in "org.xbib.jdbc.csv.CsvResultSet.CsvResultSet(CsvStatement, DataReader, String, List<Object[]>, boolean, int, LogicalExpression, List, LogicalExpression, List<Object[]>, int, int, String, int)".

The contents of "allReaderColumns" at this point in time is this:

[EXTERNAL_VALUE, code, ACTIVE, VALUE_ES, value_en, subcode, sort_index, VALUE_EN, SORT_INDEX, value_es, NAME, CODE, name, SUBCODE]

Notice that we have upper and lower versions of all the columns except for EXTERNAL_VALUE and ACTIVE, which only have uppercase versions, probably because they weren't in the where clause.

At this point, the simplest fix would be to change the referenced code block to the following:

for (Object usedColumn : this.usedColumns) {
    if (!allReaderColumns.contains(usedColumn.toUpperCase())) {
        throw new SQLException(CsvResources.getString("invalidColumnName") + ": " + usedColumn);
    }
}

But it is odd that the allReaderColumns list has two copies of all the columns that were in the select clause