pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Freyd <Oliver.Freyd@iontof.com>
To: pgsql-odbc@postgresql.org
Subject: [PATCH] SQLFreeStmt deletes params, but does not reset the stmt->prepared state.
Date: Fri, 17 Oct 2014 12:07:47 +0200
Message-ID: <m1qppj$obm$1@ger.gmane.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-odbc>

Hello,

In ResolveOneParam (convert.c:4586) there is code that converts boolean 
'-1' to '1'. This is necessary for MS Access because it uses -1 as true 
representation.

In my application, an Access 2013 frontend with a postgresql backend,
sometimes this conversion did not work, and the backend would fail like 
this:

invalid input syntax for type boolean: "-1" at character 399

The statement is like this:

DELETE FROM "public"."someview" WHERE "id" = 13020
AND ... "someboolean" = '-1' ...

This does not happen always, and I've seen it only in DELETE queries,
when I try to delete a row that has a checkbox that is checked (true).
The first try always works, the second try (deleting another row) it fails.

Now this is how it fails (IMHO):

The ResolveOneParam() function relies on the correct types being 
assigned to the parameters, In qb->ipdopts->parameters there is
SQLType and PGType. The SQLType is and enum that does not contain 
boolean, only the PGType can be boolean.

In PGAPI_Execute() (execute.c:1025) it calls prepareParameters, where
the PGTypes are found (don't know how exactly), and put into the stmt,
as stmt->ipd->ipdf.parameters.

If the PGTypes are not 0, the query runs fine. The second time
the query is executed, the query is already prepared (stmt->prepared=5)
and the prepare step is omitted. But then the PGTypes are missing,
the bool '-1' -> '1' conversion is not done and the query fails.

It turns out Access calls SQLFreeStmt(option=SQL_RESET_PARAMS),
that does SC_free_params, so the params get deleted.

But the params contain the result of the prepare call,
so IMHO the stmt->prepared state is now wrong, the transaction is no 
more prepared, so stmt->prepared should be reset to 0.

And that actually fixes the bug.


I hope this is useful, it took quite a while to track this down...

best regards,

	Oliver Freyd

-----------------------------------------------------------------------
inline patch 1: statement.c (+1/-0 lines) download inline-1.patchdiff --git a/statement.c b/statement.c index da5abf5..a019d5d 100644 --- a/statement.c +++ b/statement.c @@ -581,6 +581,7 @@ SC_free_params(StatementClass *self, char option) { APD_free_params(SC_get_APDF(self), option); IPD_free_params(SC_get_IPDF(self), option); + if (self->prepared!=NOT_YET_PREPARED)\
SC_set_prepared(self, NOT_YET_PREPARED); } PDATA_free_params(SC_get_PDTI(self), option); self->data_at_exec = -1; -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc Patches and attachments: download all (2 files, .tar.gz)
SC_free_params.patch (text/x-diff, 433B) download diff --git a/statement.c b/statement.c index da5abf5..a019d5d 100644 --- a/statement.c +++ b/statement.c @@ -581,6 +581,7 @@ SC_free_params(StatementClass *self, char option) { APD_free_params(SC_get_APDF(self), option); IPD_free_params(SC_get_IPDF(self), option); + if (self->prepared!=NOT_YET_PREPARED) SC_set_prepared(self, NOT_YET_PREPARED); } PDATA_free_params(SC_get_PDTI(self), option); self->data_at_exec = -1;

view thread (6+ messages)  latest in thread

Message-ID: <m1qppj$obm$1@ger.gmane.org>
Permalink:  ../m1qppj$obm$1@ger.gmane.org/
Also on:    postgresql.org/message-id/m1qppj$obm$1@ger.gmane.org

 ·  · 

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: Oliver.Freyd@iontof.com
  Subject: Re: [PATCH] SQLFreeStmt deletes params, but does not reset the stmt->prepared state.
  In-Reply-To: <m1qppj$obm$1@ger.gmane.org>
  References: <m1qppj$obm$1@ger.gmane.org>

* 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