Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xwgnc-0006bG-04 for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Dec 2014 00:31:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xwgnb-00023T-HH for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Dec 2014 00:31:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xwgna-00023N-ND for pgsql-hackers@postgresql.org; Fri, 05 Dec 2014 00:31:06 +0000 Received: from sl2.blur.com ([67.228.124.139] helo=vz1.blur.com) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XwgnI-0007Fn-54 for pgsql-hackers@postgresql.org; Fri, 05 Dec 2014 00:30:50 +0000 Received: (qmail 22497 invoked by uid 89); 5 Dec 2014 00:30:44 -0000 Received: from unknown (HELO mail.blur.com) (12.22.197.194) by vz1.blur.com with (DHE-RSA-AES256-SHA encrypted) SMTP; 5 Dec 2014 00:30:44 -0000 Received: (qmail 29862 invoked by uid 89); 5 Dec 2014 00:30:21 -0000 Received: by simscan 1.4.0 ppid: 29856, pid: 29860, t: 0.1066s scanners: attach: 1.4.0 Received: from plo-cr1-215-101.peak.org (HELO obsidian.localnet) (newellm@69.59.215.101) by mihoho with ESMTPA; 5 Dec 2014 00:30:21 -0000 From: Matt Newell To: Heikki Linnakangas Cc: pgsql-hackers@postgresql.org Subject: Re: libpq pipelining Date: Thu, 04 Dec 2014 16:30:19 -0800 Message-ID: <2193114.W6sD3Nzkqp@obsidian> User-Agent: KMail/4.14.2 (Linux/3.14-2-amd64; KDE/4.14.2; x86_64; ; ) In-Reply-To: <5812260.A9DG1YyGp2@obsidian> References: <2059418.jZQvL3lH90@obsidian> <5480D476.2090306@vmware.com> <5812260.A9DG1YyGp2@obsidian> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Pg-Spam-Score: -1.2 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org > > > The explanation of PQgetFirstQuery makes it sound pretty hard to match > > up the result with the query. You have to pay attention to PQisBusy. > > PQgetFirstQuery should also be valid after > calling PQgetResult and then you don't have to worry about PQisBusy, so I > should probably change the documentation to indicate that is the preferred > usage, or maybe make that the only guaranteed usage, and say the results > are undefined if you call it before calling PQgetResult. That usage also > makes it consistent with PQgetLastQuery being called immediately after > PQsendQuery. > I changed my second example to call PQgetFirstQuery after PQgetResult instead of before, and that removes the need to call PQconsumeInput and PQisBusy when you don't mind blocking. It makes the example super simple: PQsendQuery(conn, "INSERT INTO test(id) VALUES (DEFAULT),(DEFAULT) RETURNING id"); query1 = PQgetLastQuery(conn); /* Duplicate primary key error */ PQsendQuery(conn, "UPDATE test SET id=2 WHERE id=1"); query2 = PQgetLastQuery(conn); PQsendQuery(conn, "SELECT * FROM test"); query3 = PQgetLastQuery(conn); while( (result = PQgetResult(conn)) != NULL ) { curQuery = PQgetFirstQuery(conn); if (curQuery == query1) checkResult(conn,result,curQuery,PGRES_TUPLES_OK); if (curQuery == query2) checkResult(conn,result,curQuery,PGRES_FATAL_ERROR); if (curQuery == query3) checkResult(conn,result,curQuery,PGRES_TUPLES_OK); } Note that the curQuery == queryX check will work no matter how many results a query produces. Matt Newell -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers