Argh (was about an ECPG bug)

From: Lee Kindness <lkindness(at)csl(dot)co(dot)uk>
To: Michael Meskes <meskes(at)postgresql(dot)org>
Cc: PostgreSQL Interfaces <pgsql-interfaces(at)postgresql(dot)org>
Subject: Argh (was about an ECPG bug)
Date: 2001-08-09 08:13:35
Message-ID: 15218.17967.121998.588851@elsick.csl.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Michael Meskes writes:
> I just accidently deleted that mail I answered about the ECPG bug. In case
> there was just a typo in the source, i.e. ptr was indeed defined as a
> pointer, could you please resend it?

Sure:

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.

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Jeff Johnson 2001-08-09 13:51:42 Select count(*) takes a long time
Previous Message Lee Kindness 2001-08-09 08:08:00 Re: ecpg bug with SQL TYPE xxxPtr is xxx REFERENCE?