From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: pgsql-odbc@postgresql.org
Subject: SQLExecute returns 0 rows with BoolsAsChar=1
Date: Tue, 19 Mar 2013 00:25:09 +0200
Message-ID: <51479445.7020905@vmware.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-odbc>
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
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbcAttachments:0001-Fix-column_size-5-varchar-field-in-BoolsAsChar-1-mod.patch (text/x-diff, 924B) download
From 79fa21bd5c52157cf9a2296b06aa7ad6cb9c8b9c Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
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.cindex 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
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
Subject: Re: SQLExecute returns 0 rows with BoolsAsChar=1
In-Reply-To: <51479445.7020905@vmware.com>
References: <51479445.7020905@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