pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Guillaume Lelarge <guillaume@lelarge.info>
To: Brice André <brice@famille-andre.be>
Cc: Wolfe Whalen <wolfe@quios.net>
Cc: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Re: DELETE...RETURNING problem with libpq
Date: Mon, 27 May 2013 08:56:15 +0200
Message-ID: <1369637775.2987.7.camel@localhost.localdomain> (raw)
In-Reply-To: <CAOBG12nZ5fOB7=TeMezVdC9s5rmX-g+3FtW=6cJE8gtRZGcnhw@mail.gmail.com>
References: <1369483241.9028.140661235555577.5F2DB852@webmail.messagingengine.com>
	<CAOBG12ms=mgLFaR7BD7s7LckCtcT7dSYX2bUYd2A2wOGN8LaiQ@mail.gmail.com>
	<1369551079.3087.4.camel@localhost.localdomain>
	<CAOBG12nZ5fOB7=TeMezVdC9s5rmX-g+3FtW=6cJE8gtRZGcnhw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

Hi,

On Sun, 2013-05-26 at 20:35 +0200, Brice André wrote:
> [...]
> Thanks for your answer.
> 
> Your example is working fine on my computer too (I had to adapt some
> includes because my client is under Windows, but everything else was
> fine...).
> 
> But, this example is slightly different from my real code : in your
> example, the delete on the rule really deletes the element. In my code, the
> delete on the rule tags the element as deleted (with an UPDATE statement
> and a dedicated column in t1 table).
> 

Oh OK, I didn't understand that when I was working on the code.

> I slightly changed your example to be more representative of my code. Here
> are my results :
> 
>    - When executing the SQL statement from pgadmin, I get my 81 columns
>    marked as deleted and I get the 81 row results to the query.
>    - Whe executing it from your script, the function PQexecPrepared does
>    not return 'PGRES_TUPLES_OK' anymore. It now returns 'PGRES_COMMAND_OK'.
>    - From your program, the 81 rows are marked as deleted, as expected.
>    - From your program, PQntuples returns the "0" string.
>    - I did not try from php, but I expect same behaviour as with my real
>    program...
> 
> So, once modified, this example behaves like my program.
> 

It does to me too.

> I suppose that php and pgadmin use the same interface to execute the query.
> So, I suppose that there should be a solution to my problem... Do you think
> it's a bug in my version of libpq ? Or maybe is it related to the fact that
> I use prepared statement ?
> 

It took me a while to understand the difference between pgadmin/psql and
our little test program. Actually, the difference is that they don't use
PQprepare and PQexecPrepared. I've attached the new code. With
USE_PREPARED_STATEMENT defined at:
 * 0, it will simply do a PQexec of the real query
 * 1, it will do the usual PQprepare/PQexecPrepared
 * 2, it will do PQexec on the PREPARE statement, and PQexec on the
   EXECUTE statement (which is what both pgadmin and psql do)

It works with 0 and 1, not with 2. I still have no idea why. It might be
a bug, but I find it strange it's not been discovered since 8.4 (it also
doesn't work on 9.3 beta 1).


-- 
Guillaume
http://blog.guillaume.lelarge.info
http://www.dalibo.com

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Attachments:

  [application/zip] example.zip (1.8K, ../1369637775.2987.7.camel@localhost.localdomain/2-example.zip)
  download

view thread (7+ messages)  latest in thread

Message-ID: <1369637775.2987.7.camel@localhost.localdomain>
Permalink:  ../1369637775.2987.7.camel@localhost.localdomain/
Also on:    postgresql.org/message-id/1369637775.2987.7.camel@localhost.localdomain

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: guillaume@lelarge.info, brice@famille-andre.be, wolfe@quios.net
  Subject: Re: DELETE...RETURNING problem with libpq
  In-Reply-To: <1369637775.2987.7.camel@localhost.localdomain>

* 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