ECPG does not correctly identify pointer type - Mailing list pgsql-bugs

From pgsql-bugs@postgresql.org
Subject ECPG does not correctly identify pointer type
Date
Msg-id 200108140922.f7E9MHe16045@hub.org
Whole thread Raw
List pgsql-bugs
Lee Kindness (lkindness@csl.co.uk) reports a bug with a severity of 1
The lower the number the more severe it is.

Short Description
ECPG does not correctly identify pointer type

Long Description
The embedded SQL preprocessor, ecpg, does not correctly identify pointer types. Example #1 below results in the output
#2(edited for clarity) which incorrectly has references to 'ptr.id' and 'ptr.name' rather than 'ptr->id' and
'ptr->name'respectively. 

When the 'ExamplePtr ptr' definition is replaced by 'ExampleStr *ptr' the same output is produced, when changed to
'structExampleStr_ *ptr' ecpg outputs the error: 

    test.pc:16: ERROR: parse error

I am running ecpg version 2.7.1 on a Redhat Linux 7.0 system.

Sample Code
#1:

typedef struct ExampleStr_
{
  int  id;
  char name[100];
} ExampleStr, *ExamplePtr;

EXEC SQL TYPE ExampleStr IS STRUCT
{
  int  id;
  char name[100];
};
EXEC SQL TYPE ExamplePtr IS ExampleStr REFERENCE;

ExamplePtr getExample(int id)
{
  EXEC SQL BEGIN DECLARE SECTION;
  ExamplePtr ptr;
  int s_id = id;
  EXEC SQL END DECLARE SECTION;

  if( (ptr = calloc(1, sizeof(ExampleStr))) != NULL )
    {
      EXEC SQL SELECT *
    INTO :ptr
    FROM example
    WHERE id = :s_id;
    }
  return( ptr );
}

#2:

/* Processed by ecpg (2.7.1) */
/* These three include files are added by the preprocessor */
#include <ecpgtype.h>
#include <ecpglib.h>
#include <ecpgerrno.h>

typedef struct ExampleStr_
{
  int  id;
  char name[100];
} ExampleStr, *ExamplePtr;

/* exec sql type ExampleStr is struct  {
   int  id   ;
   char  name [ 100 ]   ;
 }   */
/* exec sql type ExamplePtr is ExampleStr  reference */

ExamplePtr getExample(int id)
{
  /* exec sql begin declare section */
   ExamplePtr  ptr   ;
   int  s_id  = id ;
  /* exec sql end declare section */

  if( (ptr = calloc(1, sizeof(ExampleStr))) != NULL )
    {
{ ECPGdo(__LINE__, NULL, "select  *  from example  where id  = ?     ",
    ECPGt_int,&(s_id),1L,1L,sizeof(int),
    ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
    ECPGt_int,&(ptr.id),1L,1L,sizeof(int),
    ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
    ECPGt_char,(ptr.name),100L,1L,100*sizeof(char),
    ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
    }
  return( ptr );
}

No file was uploaded with this report

pgsql-bugs by date:

Previous
From: pgsql-bugs@postgresql.org
Date:
Subject: triggers
Next
From: "Martin Kuria"
Date:
Subject: triggers