Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 81685133616B for ; Fri, 11 Mar 2011 11:35:19 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 88640-02; Fri, 11 Mar 2011 15:35:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og108.obsmtp.com (exprod7og108.obsmtp.com [64.18.2.169]) by mail.postgresql.org (Postfix) with ESMTP id 12E2B1337B92; Fri, 11 Mar 2011 11:32:39 -0400 (AST) Received: from source ([209.85.214.45]) (using TLSv1) by exprod7ob108.postini.com ([64.18.6.12]) with SMTP ID DSNKTXpAl02sJVGulYSLvWTHp/IM7BkQv7VL@postini.com; Fri, 11 Mar 2011 07:32:41 PST Received: by bwz16 with SMTP id 16so3112043bwz.32 for ; Fri, 11 Mar 2011 07:32:38 -0800 (PST) Received: by 10.204.10.21 with SMTP id n21mr2237802bkn.77.1299857558419; Fri, 11 Mar 2011 07:32:38 -0800 (PST) Received: from [85.78.66.4] (GYGMYDCCCIV.gprs.sl-laajakaista.fi [85.78.66.4]) by mx.google.com with ESMTPS id l1sm3020776bkl.13.2011.03.11.07.32.33 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 11 Mar 2011 07:32:36 -0800 (PST) Message-ID: <4D7A408C.5000800@enterprisedb.com> Date: Fri, 11 Mar 2011 17:32:28 +0200 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.1.16) Gecko/20101226 Icedove/3.0.11 MIME-Version: 1.0 To: Michael Meskes CC: Zoltan Boszormenyi , PostgreSQL Bugs Subject: Re: ecpg preprocessor regression in 9.0 References: <4CCEC145.3020409@enterprisedb.com> <4CCEC4D8.2090809@enterprisedb.com> In-Reply-To: <4CCEC4D8.2090809@enterprisedb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.2 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3 X-Spam-Level: X-Archive-Number: 201103/202 X-Sequence-Number: 29712 On 01.11.2010 15:47, Heikki Linnakangas wrote: > On 01.11.2010 15:31, Heikki Linnakangas wrote: >> This used to work in the PostgreSQL 8.4 ecpg preprocessor: >> >> EXEC SQL EXECUTE mystmt USING 1.23; >> >> but in 9.0 it throws an error: >> >> floattest.pgc:39: ERROR: variable "1" is not declared >> >> Attached is the full test case, drop it in >> src/interfaces/ecpg/test/preproc and compile. >> >> I bisected the cause to this commit: >> >> commit b2bddc2ff22f0c3d54671e43c67a2563deed7908 >> Author: Michael Meskes >> Date: Thu Apr 1 08:41:01 2010 +0000 >> >> Applied Zoltan's patch to make ecpg spit out warnings if a local >> variable hides a global one with the same name. >> >> I don't immediately see why that's causing it, but it doesn't seem >> intentional. > > On closer look, it's quite obvious: the code added to ECPGdump_a_type > thinks that ECPGt_const is a variable type, and tries to look up the > variable. The straightforward fix is this: > > diff --git a/src/interfaces/ecpg/preproc/type.c > b/src/interfaces/ecpg/preproc/type.c > index cc668a2..a53018b 100644 > --- a/src/interfaces/ecpg/preproc/type.c > +++ b/src/interfaces/ecpg/preproc/type.c > @@ -246,7 +246,7 @@ ECPGdump_a_type(FILE *o, const char *name, struct > ECPGtype * type, > struct variable *var; > > if (type->type != ECPGt_descriptor && type->type != ECPGt_sqlda && > - type->type != ECPGt_char_variable && > + type->type != ECPGt_char_variable && type->type != ECPGt_const && > brace_level >= 0) > { > char *str; > > But I wonder if there is a better way to identify variable-kind of > ECPGttypes than list the ones that are not. There's some special > ECPGttypes still missing from the above if-test, like > ECPGt_NO_INDICATOR, but I'm not sure if they can ever be passed to > ECPGdump_a_type. Seems a bit fragile anyway. This really needs to be fixed, so I just committed the above patch. The code needs some love, it took me a while to realize that find_variable() modifies its argument, for example, which explains the strdups() in ECPGdump_a_type(). And I wonder why we bother to put constants to the global all_variables list at all. And I'm not sure the above type-checks still cover everything. But at least the immediate bug has now been fixed. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com