Обсуждение: ecpg bug with SQL TYPE xxxPtr is xxx REFERENCE?

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

ecpg bug with SQL TYPE xxxPtr is xxx REFERENCE?

От
lkindness@csl.co.uk (Lee Kindness)
Дата:
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.


Re: ecpg bug with SQL TYPE xxxPtr is xxx REFERENCE?

От
Michael Meskes
Дата:
On Wed, Aug 08, 2001 at 09:07:18AM -0700, Lee Kindness wrote:
> 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;

This is not a pointer. This defines ptr to be a struct, doesn't it?

> ...

Michael
-- 
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!


Re: ecpg bug with SQL TYPE xxxPtr is xxx REFERENCE?

От
Lee Kindness
Дата:
Michael Meskes writes:> On Wed, Aug 08, 2001 at 09:07:18AM -0700, Lee Kindness wrote:> > I believe ecpg is incorrectly
handlingthe placement of results into a> > pointer to a host structure, consider the following function:> >
GeoContractorTabPtrptr;> This is not a pointer. This defines ptr to be a struct, doesn't it?
 

It's a pointer but it's conforming to some god-awful programming
practise we have in house. For example in table_strs.h there is:
/* Description of table geo_contractor from database  */typedef struct GeoContractorTabStr_{  char project_id[9];  char
contractor[53];}GeoContractorTabStr, *GeoContractorTabPtr;
 

and in table_strs_embedded.h
/* 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;
 

both are included in the C file.

Thanks, Lee Kindness.