Skip site navigation (1) Skip section navigation (2)

ecpg bug with SQL TYPE xxxPtr is xxx REFERENCE?

From: lkindness(at)csl(dot)co(dot)uk (Lee Kindness)
To: pgsql-interfaces(at)postgresql(dot)org
Subject: ecpg bug with SQL TYPE xxxPtr is xxx REFERENCE?
Date: 2001-08-08 16:07:18
Message-ID: 3fb2003d.0108080807.7ec5e135@posting.google.com (view raw or flat)
Thread:
Lists: pgsql-interfaces
Hi,

I believe ecpg is incorrectly handling the placement of results into a
pointer to a host structure, consider the following function:

GeoContractorTabPtr sel_geo_contractor_rec(char *project_id)
{ 
  EXEC SQL BEGIN DECLARE SECTION;
  GeoContractorTabPtr ptr;
  char *id;
  EXEC SQL END DECLARE SECTION;

  id = project_id;

  tab_geo_contractor = calloc(1, sizeof(GeoContractorTabStr));
  ptr = tab_geo_contractor;

  EXEC SQL SELECT *
    INTO :ptr
    FROM geo_contractor
    WHERE project_id = :id;

  return( tab_geo_contractor );
}

and the following type definitions:

/* Description of table geo_contractor from database  */
EXEC SQL TYPE GeoContractorTabStr IS STRUCT {
  char    project_id[9];
  char    contractor[53];
};
EXEC SQL TYPE GeoContractorTabPtr IS GeoContractorTabStr REFERENCE;

The following code is output by ecpg:

GeoContractorTabPtr sel_geo_contractor_rec(char *project_id)
{ 
  /* exec sql begin declare section */
   GeoContractorTabPtr  ptr   ;
   char * id   ;
  /* exec sql end declare section */

  id = project_id;
  tab_geo_contractor = calloc(1, sizeof(GeoContractorTabStr));
  ptr = tab_geo_contractor;

{ ECPGdo(__LINE__, NULL, "select  *  from geo_contractor  where
project_id  = ?     ",
	ECPGt_char,&(id),0L,1L,1*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
	ECPGt_char,(ptr.project_id),9L,1L,9*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
	ECPGt_char,(ptr.contractor),53L,1L,53*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);

  return( tab_geo_contractor );
}

Specifically ptr.project_id should be ptr->project_id and likewise for
contractor. Am I correct in this?

Thanks, Lee Kindness.

Responses

pgsql-interfaces by date

Next:From: Michael MeskesDate: 2001-08-08 18:50:22
Subject: Re: ecpg bug with SQL TYPE xxxPtr is xxx REFERENCE?
Previous:From: iafmgcDate: 2001-08-07 17:29:48
Subject: RE: pg_hba.conf and password files

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group