pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: Hiroshi Inoue <inoue@tpf.co.jp>
Cc: pgsql-odbc@postgresql.org
Subject: Re: SQLExecute returns 0 rows with BoolsAsChar=1
Date: Wed, 20 Mar 2013 15:04:07 +0200
Message-ID: <5149B3C7.5030109@vmware.com> (raw)
In-Reply-To: <514979A7.4060005@tpf.co.jp>
References: <51479445.7020905@vmware.com>
	<514979A7.4060005@tpf.co.jp>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-odbc>

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

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

Attachments:

clear-bogus-result-set-2.patch (text/x-diff, 444B) download 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)

view thread (12+ messages)  latest in thread

Message-ID: <5149B3C7.5030109@vmware.com>
Permalink:  ../5149B3C7.5030109@vmware.com/
Also on:    postgresql.org/message-id/5149B3C7.5030109@vmware.com

 ·  · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: hlinnakangas@vmware.com, inoue@tpf.co.jp
  Subject: Re: SQLExecute returns 0 rows with BoolsAsChar=1
  In-Reply-To: <5149B3C7.5030109@vmware.com>
  References: <51479445.7020905@vmware.com> <514979A7.4060005@tpf.co.jp> <5149B3C7.5030109@vmware.com>

* 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