Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xwq2J-0003RJ-4Q for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Dec 2014 10:22:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xwq2I-0008FH-Iw for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Dec 2014 10:22:54 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xwq2G-0008CE-Ni for pgsql-hackers@postgresql.org; Fri, 05 Dec 2014 10:22:52 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Xwq2D-0000lU-Ds for pgsql-hackers@postgresql.org; Fri, 05 Dec 2014 10:22:50 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id CDEE128DCE; Fri, 5 Dec 2014 02:22:47 -0800 (PST) Received: from EX13-CAS-012.vmware.com (EX13-CAS-012.vmware.com [10.113.191.64]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id C70F4B1211; Fri, 5 Dec 2014 02:22:47 -0800 (PST) Received: from EX13-MBX-024.vmware.com (10.113.191.44) by EX13-MBX-009.vmware.com (10.113.191.29) with Microsoft SMTP Server (TLS) id 15.0.913.22; Fri, 5 Dec 2014 02:23:41 -0800 Received: from [192.168.1.90] (10.113.160.246) by EX13-MBX-024.vmware.com (10.113.191.44) with Microsoft SMTP Server (TLS) id 15.0.913.22; Fri, 5 Dec 2014 02:22:46 -0800 Message-ID: <5481876E.3000701@vmware.com> Date: Fri, 5 Dec 2014 12:22:38 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.2.0 MIME-Version: 1.0 To: Matt Newell CC: Subject: Re: libpq pipelining References: <2059418.jZQvL3lH90@obsidian> <5480D476.2090306@vmware.com> <5812260.A9DG1YyGp2@obsidian> <2193114.W6sD3Nzkqp@obsidian> In-Reply-To: <2193114.W6sD3Nzkqp@obsidian> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.113.160.246] X-ClientProxiedBy: EX13-CAS-013.vmware.com (10.113.191.65) To EX13-MBX-024.vmware.com (10.113.191.44) X-Pg-Spam-Score: -6.9 (------) 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 On 12/05/2014 02:30 AM, Matt Newell wrote: >> >>> 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. Oh, that's what the PQgetLastQuery/PQgetNextQuery functions work! I didn't understand that before. I'd suggest renaming them to something like PQgetSentQuery() and PQgetResultQuery(). The first/last/next names made me think that they're used to iterate a list of queries, but in fact they're supposed to be used at very different stages. - Heikki -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers