Thread: ECPG, two varchars with same name on same line

ECPG, two varchars with same name on same line

From
Heikki Linnakangas
Date:
ECPG constructs internal struct names for VARCHAR fields using the field
name and line number it's defined on. In a contrived example, though,
that's not unique. Consider the following example:

...
EXEC SQL BEGIN DECLARE SECTION;
struct teststruct1 {
         VARCHAR a[20];
         VARCHAR b[20];
};
struct teststruct2 {
         VARCHAR a[20];
         VARCHAR b[20];
};

EXEC SQL END DECLARE SECTION;
...

This works, but if you remove all the newlines, it fails:
varcharstructs2.pgc:8: error: redefinition of ‘struct varchar_a_8’
varcharstructs2.pgc:8: error: redefinition of ‘struct varchar_b_8’

Attached is a full test case.

That hardly happens in practice, of course, but it's trivial to fix by
just adding some more salt to the struct name, like a simple counter, so
it seems we should.

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

EXEC SQL INCLUDE ../regression;

EXEC SQL BEGIN DECLARE SECTION;
struct teststruct1 {
      VARCHAR a[20];
      VARCHAR b[20];
};
struct teststruct2 {
      VARCHAR a[20];
      VARCHAR b[20];
};

EXEC SQL END DECLARE SECTION;

int main(int argc, char* argv[]) {
    EXEC SQL BEGIN DECLARE SECTION;
    struct teststruct1 ts1;
    struct teststruct2 ts2;

    EXEC SQL END DECLARE SECTION;

  ECPGdebug(1, stderr);
  EXEC SQL CONNECT TO REGRESSDB1;

  EXEC SQL SELECT 'foo', 'bar' into :ts1;
  EXEC SQL SELECT 'foz', 'baz' into :ts2;

  printf("test\na b\n%s %s\n%s %s\n", ts1.a.arr, ts1.b.arr, ts2.a.arr, ts2.b.arr);

  EXEC SQL DISCONNECT ALL;

  return 0;
}

Re: ECPG, two varchars with same name on same line

From
Michael Meskes
Date:
On Fri, May 01, 2009 at 03:49:47PM +0300, Heikki Linnakangas wrote:
> ECPG constructs internal struct names for VARCHAR fields using the field  
> name and line number it's defined on. In a contrived example, though,  
> that's not unique. Consider the following example:
> ...
> That hardly happens in practice, of course, but it's trivial to fix by  
> just adding some more salt to the struct name, like a simple counter, so  
> it seems we should.

In principle you're right. However, the change needs to be added in several
places like the internal variable structure that keeps the lineno anyway but
needs to add the counter too. BTW we can remove the lineno then I think.
Anyway, given that we are close to a release and the bug apparently never got
up in a real life usage for years I'd prefer to not change it now but wait
until the release has been done.

Comments anyone?

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


Re: ECPG, two varchars with same name on same line

From
Heikki Linnakangas
Date:
Michael Meskes wrote:
> On Fri, May 01, 2009 at 03:49:47PM +0300, Heikki Linnakangas wrote:
>> ECPG constructs internal struct names for VARCHAR fields using the field  
>> name and line number it's defined on. In a contrived example, though,  
>> that's not unique. Consider the following example:
>> ...
>> That hardly happens in practice, of course, but it's trivial to fix by  
>> just adding some more salt to the struct name, like a simple counter, so  
>> it seems we should.
> 
> In principle you're right. However, the change needs to be added in several
> places like the internal variable structure that keeps the lineno anyway but
> needs to add the counter too. BTW we can remove the lineno then I think.
> Anyway, given that we are close to a release and the bug apparently never got
> up in a real life usage for years I'd prefer to not change it now but wait
> until the release has been done.

Yeah, if the fix isn't trivial, it's not worth it.

--   Heikki Linnakangas  EnterpriseDB   http://www.enterprisedb.com


Re: ECPG, two varchars with same name on same line

From
Bruce Momjian
Date:
Michael Meskes wrote:
> On Fri, May 01, 2009 at 03:49:47PM +0300, Heikki Linnakangas wrote:
> > ECPG constructs internal struct names for VARCHAR fields using the field  
> > name and line number it's defined on. In a contrived example, though,  
> > that's not unique. Consider the following example:
> > ...
> > That hardly happens in practice, of course, but it's trivial to fix by  
> > just adding some more salt to the struct name, like a simple counter, so  
> > it seems we should.
> 
> In principle you're right. However, the change needs to be added in several
> places like the internal variable structure that keeps the lineno anyway but
> needs to add the counter too. BTW we can remove the lineno then I think.
> Anyway, given that we are close to a release and the bug apparently never got
> up in a real life usage for years I'd prefer to not change it now but wait
> until the release has been done.

Was this fixed?

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.comPG East:  http://www.enterprisedb.com/community/nav-pg-east-2010.do + If your life is a hard
drive,Christ can be your backup. +
 


Re: ECPG, two varchars with same name on same line

From
Michael Meskes
Date:
On Fri, Feb 26, 2010 at 10:23:19PM -0500, Bruce Momjian wrote:
> Was this fixed?

No, need to get along to fixing it.

Michael
-- 
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Michael at BorussiaFan dot De, Meskes at (Debian|Postgresql) dot Org
ICQ 179140304, AIM/Yahoo/Skype michaelmeskes, Jabber meskes@jabber.org
VfL Borussia! Força Barça! Go SF 49ers! Use Debian GNU/Linux, PostgreSQL


Re: ECPG, two varchars with same name on same line

From
Michael Meskes
Date:
On Fri, May 01, 2009 at 03:49:47PM +0300, Heikki Linnakangas wrote:
> ECPG constructs internal struct names for VARCHAR fields using the
> field name and line number it's defined on. In a contrived example,
> though, that's not unique. Consider the following example:
> ...

This should now be fixed.

Michael
-- 
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Michael at BorussiaFan dot De, Meskes at (Debian|Postgresql) dot Org
ICQ 179140304, AIM/Yahoo/Skype michaelmeskes, Jabber meskes@jabber.org
VfL Borussia! Força Barça! Go SF 49ers! Use Debian GNU/Linux, PostgreSQL