Обсуждение: BUG #2146: ECPG, cursros and conditional compilations...

Поиск
Список
Период
Сортировка

BUG #2146: ECPG, cursros and conditional compilations...

От
"Chuck Wegrzyn"
Дата:
The following bug has been logged online:

Bug reference:      2146
Logged by:          Chuck Wegrzyn
Email address:      cew@garbagedump.com
PostgreSQL version: 8.1.0
Operating system:   Linux
Description:        ECPG, cursros and conditional compilations...
Details:

I don't know if this is known or not, but it was a pretty interesting
"feature" to find.

I started out with a definition of a cursor:

    EXEC SQL DECLARE StoreCur CURSOR FOR
      SELECT schemaID, TenantName, Category, ModuleID,
             Argument, EncryptID, RelSpeed
      FROM Schema,Tenant WHERE Schema.TenantID =
             Tenant.TenantID;

This worked fine. When I decided I wanted to have a different cursor but
keep the old in the source I did the normal C thing...

#if 0
 <old DECLARE>
#else
 <new DECLARE>
#endif

To those of you "old hands" you are probably saying: What an idiot that
won't work! How true. When I needed to do was:

// <old DECLARE>
<new DECLAR>

I find this rather inconsistent in the way ECPG works.

Even stranger was the error I got from ECPG...

ECPG -o store.c store.ec
store.ec:146: ERROR: cursor StoreCur already defined
store.ec:411: WARNING: cursor `StoreCur´ has been declared but ot opened

make: *** [store.c] Error 3

The warning message looks like garbage insterted after the StoreCur name.

Thanks, Peace and Happy New Year.

Re: BUG #2146: ECPG, cursros and conditional compilations...

От
Michael Meskes
Дата:
On Thu, Jan 05, 2006 at 03:18:10PM +0000, Chuck Wegrzyn wrote:
> I don't know if this is known or not, but it was a pretty interesting
> "feature" to find.

It is known.

> This worked fine. When I decided I wanted to have a different cursor but
> keep the old in the source I did the normal C thing...
>
> #if 0
>  <old DECLARE>

Problem here is that ecpg processes the file BEFORE cpp does, so ecpg
does not know what this "#if 0" means. If you want to use preprocessor
commands that ecpg recognizes you should use EXEC SQL IF.

Additionally the command your were using is a pure declaration, i.e. no
executable code is associated with it. In fact standard asks ecpg to
accept a cursor declaration almost everywhere. The cursor itself is not
opened before the EXEC SQL OPEN command. So ecpg already added this
cursor definition to its internal structures, not knowing that cpp
would take away the code later on.

> To those of you "old hands" you are probably saying: What an idiot that
> won't work! How true. When I needed to do was:
>
> // <old DECLARE>

You could also use C-style comments: /* <old DECLARE> */

> I find this rather inconsistent in the way ECPG works.

Why?

> Even stranger was the error I got from ECPG...
>
> ECPG -o store.c store.ec
> store.ec:146: ERROR: cursor StoreCur already defined

So you had another definition of StoreCur, probably in the ELSE branch,
right?

> store.ec:411: WARNING: cursor `StoreCur´ has been declared but ot opened
>
> The warning message looks like garbage insterted after the StoreCur name.

This of course is true and need to be fixed. However, on my system it
does not happen:

a.pgc:27: WARNING: cursor "StoreCur" has been declared but not opened

Could you please tell me which version you are using? And on which
operating system?

Michael
--
Michael Meskes
Email: Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!