Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UHiUY-0001B5-Rf for pgsql-odbc@arkaria.postgresql.org; Mon, 18 Mar 2013 22:25:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UHiUY-0000ex-Ar for pgsql-odbc@arkaria.postgresql.org; Mon, 18 Mar 2013 22:25:18 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UHiUX-0000e3-5T for pgsql-odbc@postgresql.org; Mon, 18 Mar 2013 22:25:17 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UHiUU-0006ur-24 for pgsql-odbc@postgresql.org; Mon, 18 Mar 2013 22:25:16 +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 8FB3F2A75A for ; Mon, 18 Mar 2013 15:25:12 -0700 (PDT) Received: from zcs-prod-ext-mta-2.vmware.com (zcs-prod-ext-mta-2.vmware.com [10.113.62.224]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 826B3B062F for ; Mon, 18 Mar 2013 15:25:12 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id AA9EEC1597 for ; Mon, 18 Mar 2013 15:25:10 -0700 (PDT) X-Virus-Scanned: amavisd-new at zcs-prod-ext-mta-2.vmware.com Received: from zcs-prod-ext-mta-2.vmware.com ([127.0.0.1]) by localhost (zcs-prod-ext-mta-2.vmware.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7K7LTVg-IUK7 for ; Mon, 18 Mar 2013 15:25:10 -0700 (PDT) Received: from zcs-prod-ext-mta-2.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id 80F1FC152B for ; Mon, 18 Mar 2013 15:25:10 -0700 (PDT) Received: from [192.168.1.90] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTPSA for ; Mon, 18 Mar 2013 15:25:09 -0700 (PDT) Message-ID: <51479445.7020905@vmware.com> Date: Tue, 19 Mar 2013 00:25:09 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: pgsql-odbc@postgresql.org Subject: SQLExecute returns 0 rows with BoolsAsChar=1 Content-Type: multipart/mixed; boundary="------------080803080407020900000705" X-Pg-Spam-Score: -9.4 (---------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org This is a multi-part message in MIME format. --------------080803080407020900000705 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit If you SQLPrepare a query, and bind a VARCHAR parameter with column_size of exactly 5, and you have BoolsAsChar=1 (which is the default), the subsequent SQLExecute will return 0 rows. With those conditions, HowToPrepareBeforeExec returns shouldExec, which means that the query is sent to the server to be parse, in a Parse message. PGAPI_Execute() calls HowToPrepareBeforeExec, and calls prepareParameters(), which sends the Parse message, and reads the resulting ParameterDescription messages from the server. It also creates a new QResultClass object, and stores it as the statement's result. Now, when PGAPI_Execute() proceeds to execute the statement for real, it doesn't clear the dummy result set created by prepareParameters(), but just appends the real result set to the statement object's chain of results. When SQLExecute() returns, the first result set (the one that the application cares about) is the dummy one, with 0 rows. As a quick fix, but which I believe is quite safe and correct anyway, is to always clear any existing result sets in PGAPI_Execute() before actually executing the query. Normally, there shouldn't be any result sets, so clearing is harmless. In this buggy corner, case it clears the dummy result set, fixing the problem. Attached is a patch to fix that. As usual, this is also present in my github repository at https://github.com/hlinnaka/psqlodbc/, as well as a test case in the master-with-testcases branch. - Heikki --------------080803080407020900000705 Content-Type: text/x-diff; name="0001-Fix-column_size-5-varchar-field-in-BoolsAsChar-1-mod.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Fix-column_size-5-varchar-field-in-BoolsAsChar-1-mod.pa"; filename*1="tch" From 79fa21bd5c52157cf9a2296b06aa7ad6cb9c8b9c Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Tue, 19 Mar 2013 00:04:19 +0200 Subject: [PATCH 1/1] Fix column_size=5 varchar field in BoolsAsChar=1 mode. If a query was sent to the server using the Parse command, we returned the dummy QResult for the Parse, with 0 rows, to the caller of SQLExecute. Fix by clearing out the result set just before executing. --- execute.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/execute.c b/execute.c index 1339b58..a680dc8 100644 --- a/execute.c +++ b/execute.c @@ -1149,6 +1149,12 @@ next_param_row: } } + /* + * Clear any old result sets before executing. The prepare stage might've + * created one. + */ + SC_set_Result(stmt, NULL); + if (0 != (flag & PODBC_WITH_HOLD)) SC_set_with_hold(stmt); retval = Exec_with_parameters_resolved(stmt, &exec_end); -- 1.7.10.4 --------------080803080407020900000705 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc --------------080803080407020900000705--