Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xf4S6-0003SC-Fn for pgsql-odbc@arkaria.postgresql.org; Fri, 17 Oct 2014 10:08:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xf4S5-0000FP-Ng for pgsql-odbc@arkaria.postgresql.org; Fri, 17 Oct 2014 10:08:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xf4S5-0000FJ-4i for pgsql-odbc@postgresql.org; Fri, 17 Oct 2014 10:08:05 +0000 Received: from plane.gmane.org ([80.91.229.3]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Xf4S1-0007He-P4 for pgsql-odbc@postgresql.org; Fri, 17 Oct 2014 10:08:04 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Xf4S0-0004qR-FH for pgsql-odbc@postgresql.org; Fri, 17 Oct 2014 12:08:00 +0200 Received: from mail.iontof.com ([80.152.7.42]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 17 Oct 2014 12:08:00 +0200 Received: from Oliver.Freyd by mail.iontof.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 17 Oct 2014 12:08:00 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-odbc@postgresql.org From: Oliver Freyd Subject: [PATCH] SQLFreeStmt deletes params, but does not reset the stmt->prepared state. Date: Fri, 17 Oct 2014 12:07:47 +0200 Lines: 94 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030902090500020802080702" X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: mail.iontof.com User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 X-Pg-Spam-Score: -2.6 (--) 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. --------------030902090500020802080702 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit 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 ----------------------------------------------------------------------- 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; --------------030902090500020802080702 Content-Type: text/x-diff; name="SC_free_params.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="SC_free_params.patch" 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; --------------030902090500020802080702 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 --------------030902090500020802080702--