Received: from p1.selectacast.net (IDENT:root@p1.selectacast.net [206.41.1.251]) by hub.org (8.10.1/8.10.1) with ESMTP id e55HlxW36096 for ; Mon, 5 Jun 2000 13:47:59 -0400 (EDT) Received: from selectacast.net (IDENT:jks@d1 [209.219.91.66]) by p1.selectacast.net (8.9.3/8.9.3) with ESMTP id NAA29229; Mon, 5 Jun 2000 13:47:50 -0400 Message-ID: <393BE7C6.5F8324D3@selectacast.net> Date: Mon, 05 Jun 2000 13:47:50 -0400 From: Joseph Shraibman Organization: Xtenit X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.15 i686) X-Accept-Language: en MIME-Version: 1.0 To: Stephen Crawley CC: pgsql-interfaces@postgresql.org Subject: Re: Postgres 7.0 JDBC - update count for DELETE is always 1 References: <200006050038.e550coo17653@piglet.dstc.edu.au> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200006/28 This was supposed to be fixed already, but I guess this is just more code that didn't get into the cvs when it should have. Stephen Crawley wrote: > > 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 > >