Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UIIgs-0006FQ-AJ for pgsql-odbc@arkaria.postgresql.org; Wed, 20 Mar 2013 13:04:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UIIgr-0000w8-LK for pgsql-odbc@arkaria.postgresql.org; Wed, 20 Mar 2013 13:04:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UIIgq-0000w2-QI for pgsql-odbc@postgresql.org; Wed, 20 Mar 2013 13:04:24 +0000 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UIIgg-00047l-2U for pgsql-odbc@postgresql.org; Wed, 20 Mar 2013 13:04:23 +0000 Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 7D6BB9B60A; Wed, 20 Mar 2013 06:04:10 -0700 (PDT) Received: from zcs-prod-ext-mta-2.vmware.com (zcs-prod-ext-mta-2.vmware.com [10.113.62.224]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id 707071820C; Wed, 20 Mar 2013 06:04:10 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id 827CDC15C2; Wed, 20 Mar 2013 06:04:08 -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 Ue_TwfJKOBCU; Wed, 20 Mar 2013 06:04:08 -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 3524CC159A; Wed, 20 Mar 2013 06:04:08 -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; Wed, 20 Mar 2013 06:04:07 -0700 (PDT) Message-ID: <5149B3C7.5030109@vmware.com> Date: Wed, 20 Mar 2013 15:04:07 +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: Hiroshi Inoue CC: pgsql-odbc@postgresql.org Subject: Re: SQLExecute returns 0 rows with BoolsAsChar=1 References: <51479445.7020905@vmware.com> <514979A7.4060005@tpf.co.jp> In-Reply-To: <514979A7.4060005@tpf.co.jp> Content-Type: multipart/mixed; boundary="------------000206010007020205030505" 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. --------------000206010007020205030505 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 20.03.2013 10:56, Hiroshi Inoue wrote: > Hi, > > (2013/03/19 7:25), Heikki Linnakangas wrote: >> 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 > > I don't think it's safe. > It's in the middle of handling an array of parameter set and may > go back to next_param_row label. Ah, I see. > In addtion, apps may get out of PGAPI_Execute() in the middle of > paramater handling when there are data at execution parameters. Hmm, I don't think that's a problem. Even with data-at-execution parameters, the statement is only really going to be executed once. Until all data-at-execution parameters have filled in by the application, PGAPI_Execute() won't actually execute the statement, it will just return SQL_NEED_DATA. It's OK to reset the result set between those PGAPI_Execute() calls - there shouldn't be any results yet. The last PGAPI_Execute() call produces all the result sets. I think we're OK if we just move the SC_set_Result call to before the next_param_row label. Does the attached look right to you? - Heikki --------------000206010007020205030505 Content-Type: text/x-diff; name="clear-bogus-result-set-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="clear-bogus-result-set-2.patch" diff --git a/execute.c b/execute.c index 1339b58..4e3c533 100644 --- a/execute.c +++ b/execute.c @@ -1065,6 +1065,12 @@ mylog("prepareParameters was %s called, prepare state:%d\n", shouldParse == nCal parse_sqlsvr(stmt); } + /* + * Clear any old result sets before executing. The prepare stage might've + * created one. + */ + SC_set_Result(stmt, NULL); + next_param_row: #if (ODBCVER >= 0x0300) if (apdopts->param_operation_ptr) --------------000206010007020205030505 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 --------------000206010007020205030505--