From: Kris Jurka <books@ejurka.com>
To: Jim Gray <Jim.Gray@Bull.com>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: Suspected JDBC bug
Date: Fri, 27 Jun 2014 20:38:16 -0400 (EDT)
Message-ID: <alpine.BSO.2.03.1406272035350.15771@ejurka.com> (raw)
In-Reply-To: <707FDC874FBC4F4EA8857D4BA3D7D8F08A03804B@BUMSG1WM.fr.ad.bull.net>
References: <707FDC874FBC4F4EA8857D4BA3D7D8F08A03804B@BUMSG1WM.fr.ad.bull.net>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
On Fri, 27 Jun 2014, Jim Gray wrote:
>
> I have a test case (attached) which has this output:
>
> Message: The column name pnum was not found in this ResultSet.
>
>
The PG JDBC driver requires you to select all primary key columns to be
able to update a ResultSet. The checking for this was not correct for
multicolumn primary keys and gave you the previous error message. With
the attached patch it will say:
Updating first result set value: E2 , with new value: E9
SQL Exception processing result set for: SELECT ?
SQLState: 24000
SQLCode: 0
Message: ResultSet is not updateable. The query that generated this
result set must select only one table, and must select all primary keys
from that table. See the JDBC 2.1 API Specification, section 5.6 for more
details.
Kris Jurka=
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbcAttachments:check-updatable-primarykeys.patch (text/plain, 2.1K) downloaddiff --git a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.javaindex 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 );
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: books@ejurka.com, Jim.Gray@Bull.com
Subject: Re: Suspected JDBC bug
In-Reply-To: <alpine.BSO.2.03.1406272035350.15771@ejurka.com>
References: <707FDC874FBC4F4EA8857D4BA3D7D8F08A03804B@BUMSG1WM.fr.ad.bull.net> <alpine.BSO.2.03.1406272035350.15771@ejurka.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox