Skip to content

Commit 9a4880a

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 2132076 commit 9a4880a

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
@@ -877,8 +877,8 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_bit_field opt_initialize
877877
mmerror(PARSE_ERROR, ET_ERROR, "pointers to varchar are not implemented");
878878

879879
/* make sure varchar struct name is unique by adding a unique counter to its definition */
880-
vcn = (char *) mm_alloc(strlen($2) + sizeof(int) * CHAR_BIT * 10 / 3);
881-
sprintf(vcn, "%s_%d", $2, varchar_counter);
880+
vcn = (char *) mm_alloc(sizeof(int) * CHAR_BIT * 10 / 3);
881+
sprintf(vcn, "%d", varchar_counter);
882882
if (strcmp(dimension, "0") == 0)
883883
$$ = 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);
884884
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
@@ -75,7 +75,7 @@ main (void)
7575
char * curname3 = CURNAME ;
7676

7777
#line 27 "cursor.pgc"
78-
struct varchar_curname4_1 { int len; char arr[ 50 ]; } curname4 ;
78+
struct varchar_1 { int len; char arr[ 50 ]; } curname4 ;
7979

8080
#line 28 "cursor.pgc"
8181
char * curname5 = CURNAME ;
@@ -664,7 +664,7 @@ if (sqlca.sqlcode < 0) exit (1);}
664664

665665
strcpy(msg, "open");
666666
{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "declare $0 cursor for $1",
667-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
667+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
668668
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
669669
ECPGt_char_variable,(ECPGprepared_statement("test1", "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
670670
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
@@ -676,7 +676,7 @@ if (sqlca.sqlcode < 0) exit (1);}
676676

677677
strcpy(msg, "fetch from");
678678
{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch from $0",
679-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
679+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
680680
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
681681
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
682682
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@@ -691,7 +691,7 @@ if (sqlca.sqlcode < 0) exit (1);}
691691

692692
strcpy(msg, "fetch");
693693
{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch $0",
694-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
694+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
695695
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
696696
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
697697
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@@ -706,7 +706,7 @@ if (sqlca.sqlcode < 0) exit (1);}
706706

707707
strcpy(msg, "fetch 1 from");
708708
{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch 1 from $0",
709-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
709+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
710710
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
711711
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
712712
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@@ -724,7 +724,7 @@ if (sqlca.sqlcode < 0) exit (1);}
724724
{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch $0 from $0",
725725
ECPGt_int,&(count),(long)1,(long)1,sizeof(int),
726726
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
727-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
727+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
728728
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
729729
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
730730
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@@ -739,7 +739,7 @@ if (sqlca.sqlcode < 0) exit (1);}
739739

740740
strcpy(msg, "move");
741741
{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "move absolute 0 $0",
742-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
742+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
743743
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
744744
#line 226 "cursor.pgc"
745745

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

750750
strcpy(msg, "fetch 1");
751751
{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch 1 $0",
752-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
752+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
753753
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
754754
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
755755
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@@ -767,7 +767,7 @@ if (sqlca.sqlcode < 0) exit (1);}
767767
{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch $0 $0",
768768
ECPGt_int,&(count),(long)1,(long)1,sizeof(int),
769769
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
770-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
770+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
771771
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
772772
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
773773
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@@ -782,7 +782,7 @@ if (sqlca.sqlcode < 0) exit (1);}
782782

783783
strcpy(msg, "close");
784784
{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "close $0",
785-
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1),
785+
ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1),
786786
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
787787
#line 238 "cursor.pgc"
788788

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)
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