Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 421513b

Browse files
author
Michael Meskes
committed
Do not use the variable name when defining a varchar structure in ecpg.
With a unique counter being added anyway, there is no need anymore to have the variable name listed, too.
1 parent 6c1603c commit 421513b

File tree

8 files changed

+29
-37
lines changed

8 files changed

+29
-37
lines changed

src/interfaces/ecpg/preproc/ecpg.trailer

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,8 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_bit_field opt_initialize
872872
mmerror(PARSE_ERROR, ET_ERROR, "pointers to varchar are not implemented");
873873

874874
/* make sure varchar struct name is unique by adding a unique counter to its definition */
875-
vcn = (char *) mm_alloc(strlen($2) + sizeof(int) * CHAR_BIT * 10 / 3);
876-
sprintf(vcn, "%s_%d", $2, varchar_counter);
875+
vcn = (char *) mm_alloc(sizeof(int) * CHAR_BIT * 10 / 3);
876+
sprintf(vcn, "%d", varchar_counter);
877877
if (strcmp(dimension, "0") == 0)
878878
$$ = cat_str(7, make2_str(mm_strdup(" struct varchar_"), vcn), mm_strdup(" { int len; char arr["), mm_strdup(length), mm_strdup("]; } *"), mm_strdup($2), $4, $5);
879879
else

src/interfaces/ecpg/preproc/type.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,6 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
375375
{
376376
char *variable = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);
377377
char *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1 + strlen(varcharsize) + sizeof(int) * CHAR_BIT * 10 / 3);
378-
char *var_name,
379-
*ptr;
380378

381379
switch (type)
382380
{
@@ -398,16 +396,11 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
398396
else
399397
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
400398

401-
/* remove trailing [] is name is array element */
402-
var_name = mm_strdup(name);
403-
ptr = strchr(var_name, '[');
404-
if (ptr)
405-
*ptr = '\0';
399+
/* If we created a varchar structure atomatically, counter is greater than 0. */
406400
if (counter)
407-
sprintf(offset, "sizeof(struct varchar_%s_%d)", var_name, counter);
401+
sprintf(offset, "sizeof(struct varchar_%d)", counter);
408402
else
409-
sprintf(offset, "sizeof(struct varchar_%s)", var_name);
410-
free(var_name);
403+
sprintf(offset, "sizeof(struct varchar)");
411404
break;
412405
case ECPGt_char:
413406
case ECPGt_unsigned_char:

src/interfaces/ecpg/preproc/type.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct ECPGtype
3636
/* Everything is malloced. */
3737
void ECPGmake_struct_member(char *, struct ECPGtype *, struct ECPGstruct_member **);
3838
struct ECPGtype *ECPGmake_simple_type(enum ECPGttype, char *, int);
39-
struct ECPGtype *ECPGmake_varchar_type(enum ECPGttype, long);
4039
struct ECPGtype *ECPGmake_array_type(struct ECPGtype *, char *);
4140
struct ECPGtype *ECPGmake_struct_type(struct ECPGstruct_member *, enum ECPGttype, char *, char *);
4241
struct ECPGstruct_member *ECPGstruct_member_dup(struct ECPGstruct_member *);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
typedef struct {
3434
#line 12 "array_of_struct.pgc"
35-
struct varchar_name_1 { int len; char arr[ 50 ]; } name ;
35+
struct varchar_1 { int len; char arr[ 50 ]; } name ;
3636

3737
#line 13 "array_of_struct.pgc"
3838
int phone ;
@@ -61,7 +61,7 @@ int main()
6161

6262
typedef struct {
6363
#line 30 "array_of_struct.pgc"
64-
struct varchar_name_2 { int len; char arr[ 50 ]; } name ;
64+
struct varchar_2 { int len; char arr[ 50 ]; } name ;
6565

6666
#line 31 "array_of_struct.pgc"
6767
int phone ;
@@ -95,7 +95,7 @@ int main()
9595
#line 38 "array_of_struct.pgc"
9696
struct customer3 {
9797
#line 36 "array_of_struct.pgc"
98-
struct varchar_name_3 { int len; char arr[ 50 ]; } name ;
98+
struct varchar_3 { int len; char arr[ 50 ]; } name ;
9999

100100
#line 37 "array_of_struct.pgc"
101101
int phone ;
@@ -104,7 +104,7 @@ int main()
104104
#line 43 "array_of_struct.pgc"
105105
struct customer4 {
106106
#line 41 "array_of_struct.pgc"
107-
struct varchar_name_4 { int len; char arr[ 50 ]; } name ;
107+
struct varchar_4 { int len; char arr[ 50 ]; } name ;
108108

109109
#line 42 "array_of_struct.pgc"
110110
int phone ;
@@ -114,7 +114,7 @@ int main()
114114
int r ;
115115

116116
#line 45 "array_of_struct.pgc"
117-
struct varchar_onlyname_5 { int len; char arr[ 50 ]; } onlyname [ 2 ] ;
117+
struct varchar_5 { int len; char arr[ 50 ]; } onlyname [ 2 ] ;
118118
/* exec sql end declare section */
119119
#line 46 "array_of_struct.pgc"
120120

@@ -235,7 +235,7 @@ 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_name_4),
238+
ECPGt_varchar,&(custs4.name),(long)50,(long)1,sizeof(struct varchar_4),
239239
ECPGt_short,&(inds[0].name_ind),(long)1,(long)1,sizeof(short),
240240
ECPGt_int,&(custs4.phone),(long)1,(long)1,sizeof(int),
241241
ECPGt_short,&(inds[0].phone_ind),(long)1,(long)1,sizeof(short), ECPGt_EORT);
@@ -255,7 +255,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
255255
printf( "phone - %d\n", custs4.phone );
256256

257257
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select c from customers limit 2", ECPGt_EOIT,
258-
ECPGt_varchar,(onlyname),(long)50,(long)2,sizeof(struct varchar_onlyname_5),
258+
ECPGt_varchar,(onlyname),(long)50,(long)2,sizeof(struct varchar_5),
259259
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
260260
#line 85 "array_of_struct.pgc"
261261

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ main (void)
7474
char * curname3 = CURNAME ;
7575

7676
#line 27 "cursor.pgc"
77-
struct varchar_curname4_1 { int len; char arr[ 50 ]; } curname4 ;
77+
struct varchar_1 { int len; char arr[ 50 ]; } curname4 ;
7878

7979
#line 28 "cursor.pgc"
8080
int count ;
@@ -602,7 +602,7 @@ if (sqlca.sqlcode < 0) exit (1);}
602602

603603
strcpy(msg, "open");
604604
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare $0 cursor for $1",
605-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
605+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
606606
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
607607
ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
608608
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
@@ -614,7 +614,7 @@ if (sqlca.sqlcode < 0) exit (1);}
614614

615615
strcpy(msg, "fetch from");
616616
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from $0",
617-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
617+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
618618
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
619619
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
620620
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@@ -629,7 +629,7 @@ if (sqlca.sqlcode < 0) exit (1);}
629629

630630
strcpy(msg, "fetch");
631631
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch $0",
632-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
632+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
633633
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
634634
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
635635
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@@ -644,7 +644,7 @@ if (sqlca.sqlcode < 0) exit (1);}
644644

645645
strcpy(msg, "fetch 1 from");
646646
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 from $0",
647-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
647+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
648648
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
649649
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
650650
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@@ -662,7 +662,7 @@ if (sqlca.sqlcode < 0) exit (1);}
662662
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch $0 from $0",
663663
ECPGt_int,&(count),(long)1,(long)1,sizeof(int),
664664
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
665-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
665+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
666666
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
667667
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
668668
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@@ -677,7 +677,7 @@ if (sqlca.sqlcode < 0) exit (1);}
677677

678678
strcpy(msg, "move");
679679
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "move absolute 0 $0",
680-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
680+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
681681
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
682682
#line 216 "cursor.pgc"
683683

@@ -687,7 +687,7 @@ if (sqlca.sqlcode < 0) exit (1);}
687687

688688
strcpy(msg, "fetch 1");
689689
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 $0",
690-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
690+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
691691
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
692692
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
693693
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@@ -705,7 +705,7 @@ if (sqlca.sqlcode < 0) exit (1);}
705705
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch $0 $0",
706706
ECPGt_int,&(count),(long)1,(long)1,sizeof(int),
707707
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
708-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
708+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
709709
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
710710
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
711711
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@@ -720,7 +720,7 @@ if (sqlca.sqlcode < 0) exit (1);}
720720

721721
strcpy(msg, "close");
722722
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close $0",
723-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
723+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
724724
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
725725
#line 228 "cursor.pgc"
726726

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ main (void)
9393
c ptr = NULL ;
9494

9595
#line 36 "type.pgc"
96-
struct varchar_vc {
96+
struct varchar {
9797
#line 34 "type.pgc"
9898
int len ;
9999

@@ -150,7 +150,7 @@ main (void)
150150
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
151151
ECPGt_char,&(ptr),(long)0,(long)1,(1)*sizeof(char),
152152
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
153-
ECPGt_varchar,&(vc),(long)10,(long)1,sizeof(struct varchar_vc),
153+
ECPGt_varchar,&(vc),(long)10,(long)1,sizeof(struct varchar),
154154
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
155155
#line 68 "type.pgc"
156156

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ main (void)
7575
#line 27 "variable.pgc"
7676
struct personal_struct {
7777
#line 25 "variable.pgc"
78-
struct varchar_name_1 { int len; char arr[ BUFFERSIZ ]; } name ;
78+
struct varchar_1 { int len; char arr[ BUFFERSIZ ]; } name ;
7979

8080
#line 26 "variable.pgc"
8181
struct birthinfo birth ;
@@ -94,10 +94,10 @@ main (void)
9494
ind ind_children ;
9595
struct t1 {
9696
#line 32 "variable.pgc"
97-
struct varchar_name_2 { int len; char arr[ BUFFERSIZ ]; } name ;
97+
struct varchar_2 { int len; char arr[ BUFFERSIZ ]; } name ;
9898
} ; struct t2 {
9999
#line 32 "variable.pgc"
100-
struct varchar_name_3 { int len; char arr[ BUFFERSIZ ]; } name ;
100+
struct varchar_3 { int len; char arr[ BUFFERSIZ ]; } name ;
101101
} ;/* exec sql end declare section */
102102
#line 33 "variable.pgc"
103103

@@ -207,7 +207,7 @@ if (sqlca.sqlcode < 0) exit (1);}
207207
while (1) {
208208
strcpy(msg, "fetch");
209209
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur", ECPGt_EOIT,
210-
ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)1,sizeof(struct varchar_name_1),
210+
ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)1,sizeof(struct varchar_1),
211211
ECPGt_int,&(i->ind_name),(long)1,(long)1,sizeof(int),
212212
ECPGt_long,&(p->birth.born),(long)1,(long)1,sizeof(long),
213213
ECPGt_long,&(i->ind_birth.born),(long)1,(long)1,sizeof(long),

src/interfaces/ecpg/test/preproc/type.pgc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ main (void)
2929
struct TBempl empl;
3030
string str;
3131
c ptr = NULL;
32-
struct varchar_vc
32+
struct varchar
3333
{
3434
int len;
3535
char text[10];

0 commit comments

Comments
 (0)