diff --git a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java index 3a70818..189dd21 100644 --- a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java +++ b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java @@ -1612,6 +1612,7 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg int oidIndex = findColumnIndex( "oid" ); // 0 if not present int i = 0; + int numPKcolumns = 0; // if we find the oid then just use it @@ -1619,6 +1620,7 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg if ( oidIndex > 0 ) { i++; + numPKcolumns++; primaryKeys.add( new PrimaryKey( oidIndex, "oid" ) ); usingOID = true; } @@ -1629,13 +1631,15 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg String quotelessTableName = s[0]; String quotelessSchemaName = s[1]; java.sql.ResultSet rs = ((java.sql.Connection) connection).getMetaData().getPrimaryKeys("", quotelessSchemaName, quotelessTableName); - for (; rs.next(); i++ ) + while (rs.next()) { + numPKcolumns++; String columnName = rs.getString(4); // get the columnName - int index = findColumn( columnName ); + int index = findColumnIndex( columnName ); if ( index > 0 ) { + i++; primaryKeys.add( new PrimaryKey(index, columnName ) ); // get the primary key information } } @@ -1652,7 +1656,7 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg PSQLState.DATA_ERROR); } - updateable = primaryKeys.size() > 0; + updateable = (i == numPKcolumns); if ( connection.getLogger().logDebug() ) connection.getLogger().debug( "checking primary key " + updateable );