#14 Methods of ResultSet swaps columns with same name

open
nobody
None
5
2013-10-12
2007-04-19
Anonymous
No

Methods like

ResultSet.getInt(int columnIndex)
ResultSet.getString(int)
ResultSet.getObject(int)
etc.

returns invalid values if there is more than one column in the result set with the same name.

Discussion

  • Logged In: NO

    Analysis:
    In P6ResultSet the column index is mapped to the column name (which seems to fail if two columns have the same name):
    public String getString(int p0) throws SQLException {
    return getString(passthru.getMetaData().getColumnName(p0));
    }

    Solution:
    Directly pass the column index:

    public Object getString(int p0) throws SQLException {
    return passthru.getString(p0);
    }

     
  • Adam Hardy
    Adam Hardy
    2009-01-27

    This one foxed me for a while.

    I unfairly blamed OpenJPA, but as soon as I reduced my test project to the bare minimum, it was pretty clear that P6Spy was to blame.

    I wonder what the chances of this ever being fixed are.

     
    • Which database did this happen on? Any chance that you could supply a sample query to recreate the problem?

      If so, please update the issue on GitHub.

      https://github.com/p6spy/p6spy/issues/81