ECPG, two varchars with same name on same line - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject ECPG, two varchars with same name on same line
Date
Msg-id 49FAEFEB.6080906@enterprisedb.com
Whole thread Raw
Responses Re: ECPG, two varchars with same name on same line  (Michael Meskes <meskes@postgresql.org>)
Re: ECPG, two varchars with same name on same line  (Michael Meskes <meskes@postgresql.org>)
List pgsql-hackers
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;
}

pgsql-hackers by date:

Previous
From: Greg Stark
Date:
Subject: Re: Restore deleted rows
Next
From: Andrew Dunstan
Date:
Subject: Re: Perl coding style in postgresql