Argh (was about an ECPG bug)

Поиск
Список
Период
Сортировка
От Lee Kindness
Тема Argh (was about an ECPG bug)
Дата
Msg-id 15218.17967.121998.588851@elsick.csl.co.uk
обсуждение исходный текст
Ответ на Argh (was about an ECPG bug)  (Michael Meskes <meskes@postgresql.org>)
Список pgsql-interfaces
Michael Meskes writes:> I just accidently deleted that mail I answered about the ECPG bug. In case> there was just a
typoin 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.


В списке pgsql-interfaces по дате отправления:

Предыдущее
От: Lee Kindness
Дата:
Сообщение: Re: ecpg bug with SQL TYPE xxxPtr is xxx REFERENCE?
Следующее
От: "Jeff Johnson"
Дата:
Сообщение: Select count(*) takes a long time