pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephen Crawley <crawley@dstc.edu.au>
To: pgsql-interfaces@postgresql.org
Subject: Postgres 7.0 JDBC - update count for DELETE is always 1
Date: Mon, 05 Jun 2000 10:38:57 +1000
Message-ID: <200006050038.e550coo17653@piglet.dstc.edu.au> (raw)


Hi,

I'm trying to port a large JDBC application to Postgres 7.0 from MySQL,
and I've run into what I believe is a bug in the JDBC driver.

When my application executes a "DELETE" statement, the ResultSet entry
always says that 1 row has been deleted.  Even when nothing has been
deleted.  I did a bit of investigation, and I think I've found where the
problem is.  In the class postgresql.Connection, the method 

   public java.sql.ResultSet ExecSQL(String sql) throws SQLException

contains the following code:

  ...

  int update_count = 1;

  ...		
	
  case 'C':	// Command Status
    recv_status = pg_stream.ReceiveString(8192);
				
    // Now handle the update count correctly.
    if(recv_status.startsWith("INSERT") || recv_status.startsWith("UPDATE")) {
      try {
       update_count = 
         Integer.parseInt(recv_status.substring(1+recv_status.lastIndexOf(' 
')));
      } catch(NumberFormatException nfe) {
      throw new PSQLException("postgresql.con.fathom",recv_status);
      }
    }

  ...

It looks like the code picks out the update count when the query was
described (by the backend) as an INSERT or UPDATE.  But it does not
do this for a DELETE.

I looked at the source of the backend (src/backend/tcop/dest.c, etc) and
it does seem to return an update count for the CMD_DELETE command.  If
I've got this right, adding

   ... || recv_status.startsWith("DELETE") ...

to the if statement should fix the problem.

-- Steve

  




view thread (7+ messages)  latest in thread

Message-ID: <200006050038.e550coo17653@piglet.dstc.edu.au>
Permalink:  ../200006050038.e550coo17653@piglet.dstc.edu.au/
Also on:    postgresql.org/message-id/200006050038.e550coo17653@piglet.dstc.edu.au

 · 

reply

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-interfaces@postgresql.org
  Cc: crawley@dstc.edu.au
  Subject: Re: Postgres 7.0 JDBC - update count for DELETE is always 1
  In-Reply-To: <200006050038.e550coo17653@piglet.dstc.edu.au>
  References: <200006050038.e550coo17653@piglet.dstc.edu.au>

* 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