[libpostgresql-jdbc-java] 01/04: The JDBC spec says that when you have two duplicately named columns, a search by name should return the first one.
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:20:10 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_1_412
in repository libpostgresql-jdbc-java.
commit 01fce9c1cbc86c93badd55ea3d65f0581c7062e2
Author: Kris Jurka <books at ejurka.com>
Date: Mon Jan 14 10:24:07 2008 +0000
The JDBC spec says that when you have two duplicately named columns,
a search by name should return the first one.
Magne Mahre
---
org/postgresql/jdbc2/AbstractJdbc2ResultSet.java | 5 ++++-
org/postgresql/test/jdbc2/ResultSetTest.java | 12 ++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
index 189b975..d261bc4 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
@@ -2366,7 +2366,10 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
if (columnNameIndexMap == null)
{
columnNameIndexMap = new HashMap(fields.length * 2);
- for (int i = 0; i < fields.length; i++)
+ // The JDBC spec says when you have duplicate columns names,
+ // the first one should be returned. So load the map in
+ // reverse order so the first ones will overwrite later ones.
+ for (int i = fields.length - 1; i >= 0; i--)
{
columnNameIndexMap.put(fields[i].getColumnLabel().toLowerCase(), new Integer(i + 1));
}
diff --git a/org/postgresql/test/jdbc2/ResultSetTest.java b/org/postgresql/test/jdbc2/ResultSetTest.java
index fd09714..b669fa8 100644
--- a/org/postgresql/test/jdbc2/ResultSetTest.java
+++ b/org/postgresql/test/jdbc2/ResultSetTest.java
@@ -693,4 +693,16 @@ public class ResultSetTest extends TestCase
try { rs.clearWarnings(); fail("Expected SQLException"); }
catch (SQLException e) { }
}
+
+ /*
+ * The JDBC spec says when you have duplicate column names,
+ * the first one should be returned.
+ */
+ public void testDuplicateColumnNameOrder() throws SQLException
+ {
+ Statement stmt = con.createStatement();
+ ResultSet rs = stmt.executeQuery("SELECT 1 AS a, 2 AS a");
+ assertTrue(rs.next());
+ assertEquals(1, rs.getInt("a"));
+ }
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git
More information about the pkg-java-commits
mailing list