Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YQdsU-0004rQ-22 for pgsql-odbc@arkaria.postgresql.org; Wed, 25 Feb 2015 15:27:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YQdsT-0008Nd-FT for pgsql-odbc@arkaria.postgresql.org; Wed, 25 Feb 2015 15:27:57 +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 1YQdsS-0008M0-N5 for pgsql-odbc@postgresql.org; Wed, 25 Feb 2015 15:27:56 +0000 Received: from mail.iontof.com ([80.152.7.42]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YQdsO-0003KH-4w for pgsql-odbc@postgresql.org; Wed, 25 Feb 2015 15:27:55 +0000 Received: from localhost (mail.iontof.com [127.0.0.1]) by localhost (Postfix) with ESMTP id 1F00E1DB2065 for ; Wed, 25 Feb 2015 16:27:51 +0100 (CET) X-Virus-Scanned: amavisd-new X-Spam-Flag: NO X-Spam-Score: -10 X-Spam-Level: X-Spam-Status: No, score=-10 required=5 tests=[ALL_TRUSTED=-10] autolearn=disabled Received: from mail.iontof.com ([127.0.0.1]) by localhost (mail.iontof.com [127.0.0.1]) (amavisd-new, port 10033) with ESMTP id H7OdHGfPelLN for ; Wed, 25 Feb 2015 16:27:49 +0100 (CET) Received: from [192.168.0.87] (Oliver3.iontof.lan [192.168.0.87]) by mail.iontof.com (Postfix) with ESMTPSA id 6B8C71DB2001 for ; Wed, 25 Feb 2015 16:27:49 +0100 (CET) Message-ID: <54EDE9F4.5090002@iontof.com> Date: Wed, 25 Feb 2015 16:27:48 +0100 From: Oliver Freyd User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: pgsql-odbc@postgresql.org Subject: Re: Re: [PATCH] SQLFreeStmt deletes params, but does not reset the stmt->prepared state. References: <55BAADA01D8C504993894EAEA7517CF80ED85E@003FCH1MPN2-002.003f.mgd2.msft.net> In-Reply-To: <55BAADA01D8C504993894EAEA7517CF80ED85E@003FCH1MPN2-002.003f.mgd2.msft.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) 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 Hi, I think I'm using the psql-odbc driver hand-patched with IPD_free_params() commented out, like you said, and it works fine for us. Isnt' this already merged into the git repository? I thought it sounded pretty obvious at the time when I found it, didn't bother to check afterwards... greets, Oliver Am 24.02.2015 um 16:03 schrieb Faith, Jeremy: > Hi, > > I also found this issue with the PHP odbc extension which uses > SQL_RESET_PARAMS. > It causes the following error on the second odbc_execute() call. > PHP Warning: odbc_execute(): SQL error: Unfortunatley couldn't get this > paramater's info, SQL state S1000 in SQLDescribeParameter > > > >Hi Oliver, > > > >On 2014/10/17 19:07, Oliver Freyd wrote: > >> 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... > > > >Thank you for your investigation. > > > >According to the following pages > > http://msdn.microsoft.com/en-us/library/ms709284%28v=vs.85%29.aspx > > http://msdn.microsoft.com/en-us/library/ms710926%28v=vs.85%29.aspx > > > >, it seems better to reset APD only keeping IPD intact. > > > >Comments? > > > I tried Oliver's patch and PHP no longer has a problem. > Inserting 100,000 rows into a simple table takes 47.6s > No sign of any memory leak. > > On the other hand commenting out the IPD_free_params() call also works. > Same 100,000 inserts take 34.1s, so significantly faster. > Again no sign of a memory leak. I also tried prepare,execute,free 100K > times, much slower but again no sign of a memory leak. > > I think the SC_Destructor() function will free the IPD params if nothing > else does. So, unless there is some other path that could cause a leak, > I would say just commenting out the IPD_free_params() call is a better > solution. > > Regards, > Jeremy Faith > > > > >regards, > >Hiroshi Inoue > > > >> 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; > >> > >> > >> > Tyco Safety Products/CEM Systems Ltd. > ------------------------------------------------------------------------ > > This e-mail contains privileged and confidential information intended > for the use of the addressees named above. If you are not the intended > recipient of this e-mail, you are hereby notified that you must not > disseminate, copy or take any action in respect of any information > contained in it. If you have received this e-mail in error, please > notify the sender immediately by e-mail and immediately destroy this > e-mail and its attachments. -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc