Wrong column names in ResultSetMetaData
От | Mike Martin |
---|---|
Тема | Wrong column names in ResultSetMetaData |
Дата | |
Msg-id | ce9dna$pne$1@news.hub.org обсуждение исходный текст |
Список | pgsql-jdbc |
With the new V3 driver the column names in ResultSetMetaData don't reflect the aliases used in the SQL. I.e. if I do: SELECT name as name_alias FROM ... the metadata says I have a result column called "name" instead of "name_alias". Client: PostgreSQL 7.5devel JDBC2 with SSL (build 304) Server: PostgreSQL 7.4.2 on i386-redhat-linux-gnu, compiled by GCC 2.96 The code below works with the 7.4 driver but fails with 7.5. Is this more likely to be in the driver or in the server-side V3 code? Mike AliasTest.java ------------------- import java.sql.*; import java.util.*; public class AliasTest { public static void main(String args[]) throws Exception { if (args.length != 3) throw new IllegalArgumentException("usage: java AliasTest <database_spec> <username> <password>"); Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql:" + args[0], args[1], args[2]); Statement stmt = conn.createStatement(); try { stmt.execute("DROP TABLE alias_test"); } catch (SQLException e) {} stmt.execute("CREATE TABLE alias_test ( name varchar(64) not null primary key )"); stmt.executeUpdate("INSERT INTO alias_test ( name ) VALUES ( 'abc' )"); stmt.close(); PreparedStatement ps = conn.prepareStatement("SELECT name as name_alias FROM alias_test"); ResultSet rs = ps.executeQuery(); if (!rs.next()) throw new Exception("No row?"); List expectedColumnNames = Arrays.asList(new String[] { "name_alias" }); List actualColumnNames = new ArrayList(); ResultSetMetaData rsmd = rs.getMetaData(); int colCount = rsmd.getColumnCount(); for (int colNum = 1; colNum <= colCount; ++colNum) actualColumnNames.add(rsmd.getColumnName(colNum)); if (!expectedColumnNames.equals(actualColumnNames)) throw new Exception("Wrong column names in result set metadata, expected " + expectedColumnNames + ", got " + actualColumnNames); rs.close(); ps.close(); conn.close(); } }
В списке pgsql-jdbc по дате отправления: