Skip to content

Commit f917968

Browse files
author
Michael Meskes
committed
Several fixes to array handling in ecpg.
Patches by Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
1 parent 0c4ea7a commit f917968

11 files changed

+556
-38
lines changed

src/interfaces/ecpg/preproc/type.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const int bra
303303

304304
ECPGdump_a_simple(o, name,
305305
type->u.element->type,
306-
type->u.element->size, type->size, NULL, prefix, type->u.element->counter);
306+
type->u.element->size, type->size, struct_sizeof ? struct_sizeof : NULL,
307+
prefix, type->u.element->counter);
307308

308309
if (ind_type != NULL)
309310
{
@@ -519,11 +520,19 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
519520
sprintf(offset, "sizeof(%s)", ecpg_type_name(type));
520521
break;
521522
}
522-
523-
if (atoi(arrsize) < 0)
523+
524+
/*
525+
* Array size would be -1 for addresses of members within structure,
526+
* when pointer to structure is being dumped.
527+
*/
528+
if (atoi(arrsize) < 0 && !siz)
524529
strcpy(arrsize, "1");
525530

526-
if (siz == NULL || strlen(siz) == 0 || strcmp(arrsize, "0") == 0 || strcmp(arrsize, "1") == 0)
531+
/*
532+
* If siz i.e. the size of structure of which this variable is part of,
533+
* that gives the offset to the next element, if required
534+
*/
535+
if (siz == NULL || strlen(siz) == 0)
527536
fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, offset);
528537
else
529538
fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, siz);

src/interfaces/ecpg/test/ecpg_schedule

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ test: pgtypeslib/num_test
1717
test: pgtypeslib/num_test2
1818
test: pgtypeslib/nan_test
1919
test: preproc/array_of_struct
20+
test: preproc/pointer_to_struct
2021
test: preproc/autoprep
2122
test: preproc/comment
2223
test: preproc/cursor

src/interfaces/ecpg/test/expected/preproc-array_of_struct.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ if (sqlca.sqlcode < 0) sqlprint();}
235235
}
236236

237237
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from customers limit 1", ECPGt_EOIT,
238-
ECPGt_varchar,&(custs4.name),(long)50,(long)1,sizeof(struct varchar_4),
239-
ECPGt_short,&(inds[0].name_ind),(long)1,(long)1,sizeof(short),
240-
ECPGt_int,&(custs4.phone),(long)1,(long)1,sizeof(int),
241-
ECPGt_short,&(inds[0].phone_ind),(long)1,(long)1,sizeof(short), ECPGt_EORT);
238+
ECPGt_varchar,&(custs4.name),(long)50,(long)1,sizeof( struct customer4 ),
239+
ECPGt_short,&(inds[0].name_ind),(long)1,(long)1,sizeof( struct ind ),
240+
ECPGt_int,&(custs4.phone),(long)1,(long)1,sizeof( struct customer4 ),
241+
ECPGt_short,&(inds[0].phone_ind),(long)1,(long)1,sizeof( struct ind ), ECPGt_EORT);
242242
#line 80 "array_of_struct.pgc"
243243

244244
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();

src/interfaces/ecpg/test/expected/preproc-outofscope.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,16 @@ static void
202202
open_cur1(void)
203203
{
204204
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur cursor for select * from a1", ECPGt_EOIT,
205-
ECPGt_int,&((*( MYTYPE *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof(int),
206-
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof(int),
207-
ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).t),(long)64,(long)1,(64)*sizeof(char),
208-
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof(int),
209-
ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof(double),
210-
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof(int),
211-
ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof(double),
212-
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof(int),
213-
ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).c),(long)30,(long)1,(30)*sizeof(char),
214-
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof(int), ECPGt_EORT);
205+
ECPGt_int,&((*( MYTYPE *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof( struct mytype ),
206+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof( struct mynulltype ),
207+
ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).t),(long)64,(long)1,sizeof( struct mytype ),
208+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof( struct mynulltype ),
209+
ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof( struct mytype ),
210+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof( struct mynulltype ),
211+
ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof( struct mytype ),
212+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof( struct mynulltype ),
213+
ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).c),(long)30,(long)1,sizeof( struct mytype ),
214+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof( struct mynulltype ), ECPGt_EORT);
215215
#line 40 "outofscope.pgc"
216216

217217
if (sqlca.sqlcode < 0) exit (1);}
@@ -226,16 +226,16 @@ static void
226226
get_record1(void)
227227
{
228228
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch mycur", ECPGt_EOIT,
229-
ECPGt_int,&((*( MYTYPE *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof(int),
230-
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof(int),
231-
ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).t),(long)64,(long)1,(64)*sizeof(char),
232-
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof(int),
233-
ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof(double),
234-
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof(int),
235-
ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof(double),
236-
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof(int),
237-
ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).c),(long)30,(long)1,(30)*sizeof(char),
238-
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof(int), ECPGt_EORT);
229+
ECPGt_int,&((*( MYTYPE *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof( struct mytype ),
230+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof( struct mynulltype ),
231+
ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).t),(long)64,(long)1,sizeof( struct mytype ),
232+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof( struct mynulltype ),
233+
ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof( struct mytype ),
234+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof( struct mynulltype ),
235+
ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof( struct mytype ),
236+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof( struct mynulltype ),
237+
ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).c),(long)30,(long)1,sizeof( struct mytype ),
238+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof( struct mynulltype ), ECPGt_EORT);
239239
#line 49 "outofscope.pgc"
240240

241241
if (sqlca.sqlcode < 0) exit (1);}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy