Skip to content

Commit

Permalink
Fixup fetching all metadata for a ResultSet at once for 7.4 servers.
Browse files Browse the repository at this point in the history
7.4 does not support row IN operations (a,b) IN ((c,d),(e,f)).  So
we've got to fake that with a JOIN.
  • Loading branch information
jurka committed Apr 2, 2011
1 parent 24e4e35 commit 059e501
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2004-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java,v 1.24 2010/12/26 01:20:21 jurka Exp $
* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java,v 1.25 2011/04/02 11:09:26 jurka Exp $
*
*-------------------------------------------------------------------------
*/
Expand Down Expand Up @@ -206,29 +206,36 @@ private void fetchFieldMetaData() throws SQLException {
sql.append("JOIN pg_catalog.pg_attribute a ON (c.oid = a.attrelid) ");
sql.append("JOIN pg_catalog.pg_type t ON (a.atttypid = t.oid) ");
sql.append("LEFT JOIN pg_catalog.pg_attrdef d ON (d.adrelid = a.attrelid AND d.adnum = a.attnum) ");
sql.append("WHERE (c.oid, a.attnum) IN (");
sql.append("JOIN (");

// 7.4 servers don't support row IN operations (a,b) IN ((c,d),(e,f))
// so we've got to fake that with a JOIN here.
//
boolean hasSourceInfo = false;
for (int i=0; i<fields.length; i++) {
if (fields[i].getTableOid() == 0)
continue;

if (hasSourceInfo)
sql.append(", ");
else
hasSourceInfo = true;
sql.append(" UNION ALL ");

sql.append("(");
sql.append("SELECT ");
sql.append(fields[i].getTableOid());
if (!hasSourceInfo)
sql.append(" AS oid ");
sql.append(", ");
sql.append(fields[i].getPositionInTable());
sql.append(")");
if (!hasSourceInfo)
sql.append(" AS attnum");

if (!hasSourceInfo)
hasSourceInfo = true;
}
sql.append(")");
sql.append(") vals ON (c.oid = vals.oid AND a.attnum = vals.attnum) ");

if (!hasSourceInfo)
return;

Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql.toString());
while (rs.next()) {
Expand Down

0 comments on commit 059e501

Please sign in to comment.