Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hSD6t-0006lB-IT for pgsql-odbc@arkaria.postgresql.org; Sun, 19 May 2019 04:07:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hSD5r-0001VD-No for pgsql-odbc@arkaria.postgresql.org; Sun, 19 May 2019 04:06:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hSD5r-0001V5-DQ for pgsql-odbc@lists.postgresql.org; Sun, 19 May 2019 04:06:39 +0000 Received: from mail03.asahi-net.or.jp ([202.224.55.15]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hSD5h-00053V-Hq for pgsql-odbc@lists.postgresql.org; Sun, 19 May 2019 04:06:37 +0000 Received: from [192.168.0.6] (KD124208079206.ppp-bb.dion.ne.jp [124.208.79.206]) (Authenticated sender: GQ9H-INUE) by mail03.asahi-net.or.jp (Postfix) with ESMTPA id A6D634483E; Sun, 19 May 2019 13:06:23 +0900 (JST) Subject: Re: Bound parameters in escaped functions From: "Inoue, Hiroshi" To: Grant Shirreffs Cc: "pgsql-odbc@lists.postgresql.org" References: Message-ID: <697c5065-225a-e0e0-fd64-c16a18ae45d6@dream.email.ne.jp> Date: Sun, 19 May 2019 13:06:21 +0900 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------0116785B586EB0BF2A3DADA1" Content-Language: en-US X-Antivirus: AVG (VPS 190518-4, 2019/05/19), Outbound message X-Antivirus-Status: Clean List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------0116785B586EB0BF2A3DADA1 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi Grant, I've pushed changes to git. Please look at     https://git.postgresql.org/gitweb/?p=psqlodbc.git;a=summary . regards, Hiroshi Inoue On 2019/05/17 9:48, Inoue, Hiroshi wrote: > Hi Grant, > > Thanks for the report. > I would take care of the bug fix. > > regards, > Hiroshi Inoue > > On 2019/05/14 12:58, Grant Shirreffs wrote: >> >> Hello, >> >> I have found a bug in the translation of ‘?’ parameters in escaped >> ODBC functions. >> >> Where there is an escaped ODBC function within another, for example: >> >>                 CASE WHEN {fn LENGTH({fn LTRIM(Name || ?))=?     […] >> >> During convert_escape (convert.c:5471), at line 5626 the QueryBuild >> object is copied to a local temporary (‘ncb’), which is then passed >> to ‘processParameters’, which then calls recursively back into >> convert_escape for the inner function. >> >> Then, at line 5771, the parameter number from ncb is passed back into >> the original QueryBuild, so that query processing carries on >> successfully.  However, crucially, the dollar_number value from ncb, >> which has been incremented while processing the parameters inside the >> function, is not passed back.  So although the parameters themselves >> are correctly handled, the incorrect PostgreSQL placeholder symbol is >> generated. >> >> In the example above, the resulting SQL is: >> >>                 CASE WHEN LENGTH(LTRIM(Name || $1))=$1::int4   […] >> >> Where it should of course be: >> >>                 CASE WHEN LENGTH(LTRIM(Name) || $1))=$2:int4 >> >> The fix is to copy the dollar_number back from ncb to the original >> QueryBuild: >> >> if (SQL_ERROR != retval) >> >>             { >> >>                   qb->param_number = nqb.param_number; >> >>                   qb->dollar_number = nqb.dollar_number; >> >>                   qb->flags = nqb.flags; >> >>             } >> --- このメールは、AVG によってウイルス チェックされています。 http://www.avg.com --------------0116785B586EB0BF2A3DADA1 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit Hi Grant,

I've pushed changes to git.
Please look at
    https://git.postgresql.org/gitweb/?p=psqlodbc.git;a=summary .

regards,
Hiroshi Inoue

On 2019/05/17 9:48, Inoue, Hiroshi wrote:
Hi Grant,

Thanks for the report.
I would take care of the bug fix.

regards,
Hiroshi Inoue

On 2019/05/14 12:58, Grant Shirreffs wrote:

Hello,

 

I have found a bug in the translation of ‘?’ parameters in escaped ODBC functions.

 

Where there is an escaped ODBC function within another, for example:

 

                CASE WHEN {fn LENGTH({fn LTRIM(Name || ?))=?     […]

 

During convert_escape (convert.c:5471), at line 5626 the QueryBuild object is copied to a local temporary (‘ncb’), which is then passed to ‘processParameters’, which then calls recursively back into convert_escape for the inner function.

 

Then, at line 5771, the parameter number from ncb is passed back into the original QueryBuild, so that query processing carries on successfully.  However, crucially, the dollar_number value from ncb, which has been incremented while processing the parameters inside the function, is not passed back.  So although the parameters themselves are correctly handled, the incorrect PostgreSQL placeholder symbol is generated.

 

In the example above, the resulting SQL is:

 

                CASE WHEN LENGTH(LTRIM(Name || $1))=$1::int4   […]

 

Where it should of course be:

 

                CASE WHEN LENGTH(LTRIM(Name) || $1))=$2:int4

 

The fix is to copy the dollar_number back from ncb to the original QueryBuild:

 

            if (SQL_ERROR != retval)

            {

                  qb->param_number = nqb.param_number;

                  qb->dollar_number = nqb.dollar_number;

                  qb->flags = nqb.flags;

            }


ウイルス フリー。 www.avg.com
--------------0116785B586EB0BF2A3DADA1--