Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9fbc6d5

Browse files
committed
Fix possible omission of variable storage markers in ECPG.
The ECPG preprocessor converted code such asstatic varchar str1[10], str2[20], str3[30];intostatic struct varchar_1 { int len; char arr[ 10 ]; } str1 ; struct varchar_2 { int len; char arr[ 20 ]; } str2 ; struct varchar_3 { int len; char arr[ 30 ]; } str3 ;thus losing the storage attribute for the later variables.Repeat the declaration for each such variable.(Note that this occurred only for variables declared "varchar"or "bytea", which may help explain how it escaped detectionfor so long.)Andrey SokolovDiscussion:https://postgr.es/m/942241662288242@mail.yandex.ru
1 parent23fe89a commit9fbc6d5

File tree

6 files changed

+151
-123
lines changed

6 files changed

+151
-123
lines changed

‎src/interfaces/ecpg/preproc/ecpg.trailer

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,10 @@ type_declaration: S_TYPEDEF
425425
$$ = mm_strdup("");
426426
};
427427

428-
var_declaration: storage_declaration
429-
var_type
428+
var_declaration:
429+
storage_declarationvar_type
430430
{
431+
actual_type[struct_level].type_storage = $1;
431432
actual_type[struct_level].type_enum = $2.type_enum;
432433
actual_type[struct_level].type_str = $2.type_str;
433434
actual_type[struct_level].type_dimension = $2.type_dimension;
@@ -442,6 +443,7 @@ var_declaration: storage_declaration
442443
}
443444
| var_type
444445
{
446+
actual_type[struct_level].type_storage = EMPTY;
445447
actual_type[struct_level].type_enum = $1.type_enum;
446448
actual_type[struct_level].type_str = $1.type_str;
447449
actual_type[struct_level].type_dimension = $1.type_dimension;
@@ -850,7 +852,7 @@ variable_list: variable
850852
| variable_list ',' variable
851853
{
852854
if (actual_type[struct_level].type_enum == ECPGt_varchar || actual_type[struct_level].type_enum == ECPGt_bytea)
853-
$$ = cat_str(3, $1, mm_strdup(";"), $3);
855+
$$ = cat_str(4, $1, mm_strdup(";"), mm_strdup(actual_type[struct_level].type_storage), $3);
854856
else
855857
$$ = cat_str(3, $1, mm_strdup(","), $3);
856858
}

‎src/interfaces/ecpg/preproc/type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct exec
114114

115115
structthis_type
116116
{
117+
char*type_storage;
117118
enumECPGttypetype_enum;
118119
char*type_str;
119120
char*type_dimension;

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

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ main (void)
7171

7272

7373

74+
75+
7476

7577
#line 27 "variable.pgc"
7678
structpersonal_struct {
@@ -98,27 +100,33 @@ main (void)
98100
} ;structt2 {
99101
#line 32 "variable.pgc"
100102
structvarchar_3 {intlen;chararr[BUFFERSIZ ]; }name ;
101-
} ;/* exec sql end declare section */
103+
} ;
102104
#line 33 "variable.pgc"
105+
staticstructvarchar_4 {intlen;chararr[50 ]; }vc1 ;staticstructvarchar_5 {intlen;chararr[50 ]; }vc2 ;staticstructvarchar_6 {intlen;chararr[255 ]; }vc3 ;
106+
107+
#line 34 "variable.pgc"
108+
staticinti1 ,i2 ,i3 ;
109+
/* exec sql end declare section */
110+
#line 35 "variable.pgc"
103111

104112

105113

106-
#line35 "variable.pgc"
114+
#line37 "variable.pgc"
107115
char*married=NULL ;
108116

109-
#line35 "variable.pgc"
117+
#line37 "variable.pgc"
110118

111119

112-
#line36 "variable.pgc"
120+
#line38 "variable.pgc"
113121
longind_married ;
114122

115-
#line36 "variable.pgc"
123+
#line38 "variable.pgc"
116124

117125

118-
#line37 "variable.pgc"
126+
#line39 "variable.pgc"
119127
indchildren ;
120128

121-
#line37 "variable.pgc"
129+
#line39 "variable.pgc"
122130

123131
intloopcount;
124132
charmsg[128];
@@ -127,78 +135,78 @@ main (void)
127135

128136
strcpy(msg,"connect");
129137
{ECPGconnect(__LINE__,0,"ecpg1_regression" ,NULL,NULL ,NULL,0);
130-
#line44 "variable.pgc"
138+
#line46 "variable.pgc"
131139

132140
if (sqlca.sqlcode<0)exit (1);}
133-
#line44 "variable.pgc"
141+
#line46 "variable.pgc"
134142

135143

136144
strcpy(msg,"set");
137145
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"set datestyle to iso",ECPGt_EOIT,ECPGt_EORT);
138-
#line47 "variable.pgc"
146+
#line49 "variable.pgc"
139147

140148
if (sqlca.sqlcode<0)exit (1);}
141-
#line47 "variable.pgc"
149+
#line49 "variable.pgc"
142150

143151

144152
strcpy(msg,"create");
145153
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"create table family ( name char ( 8 ) , born integer , age smallint , married date , children integer )",ECPGt_EOIT,ECPGt_EORT);
146-
#line50 "variable.pgc"
154+
#line52 "variable.pgc"
147155

148156
if (sqlca.sqlcode<0)exit (1);}
149-
#line50 "variable.pgc"
157+
#line52 "variable.pgc"
150158

151159

152160
strcpy(msg,"insert");
153161
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"insert into family ( name , married , children ) values ( 'Mum' , '19870714' , 3 )",ECPGt_EOIT,ECPGt_EORT);
154-
#line53 "variable.pgc"
162+
#line55 "variable.pgc"
155163

156164
if (sqlca.sqlcode<0)exit (1);}
157-
#line53 "variable.pgc"
165+
#line55 "variable.pgc"
158166

159167
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"insert into family ( name , born , married , children ) values ( 'Dad' , '19610721' , '19870714' , 3 )",ECPGt_EOIT,ECPGt_EORT);
160-
#line54 "variable.pgc"
168+
#line56 "variable.pgc"
161169

162170
if (sqlca.sqlcode<0)exit (1);}
163-
#line54 "variable.pgc"
171+
#line56 "variable.pgc"
164172

165173
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"insert into family ( name , age ) values ( 'Child 1' , 16 )",ECPGt_EOIT,ECPGt_EORT);
166-
#line55 "variable.pgc"
174+
#line57 "variable.pgc"
167175

168176
if (sqlca.sqlcode<0)exit (1);}
169-
#line55 "variable.pgc"
177+
#line57 "variable.pgc"
170178

171179
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"insert into family ( name , age ) values ( 'Child 2' , 14 )",ECPGt_EOIT,ECPGt_EORT);
172-
#line56 "variable.pgc"
180+
#line58 "variable.pgc"
173181

174182
if (sqlca.sqlcode<0)exit (1);}
175-
#line56 "variable.pgc"
183+
#line58 "variable.pgc"
176184

177185
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"insert into family ( name , age ) values ( 'Child 3' , 9 )",ECPGt_EOIT,ECPGt_EORT);
178-
#line57 "variable.pgc"
186+
#line59 "variable.pgc"
179187

180188
if (sqlca.sqlcode<0)exit (1);}
181-
#line57 "variable.pgc"
189+
#line59 "variable.pgc"
182190

183191

184192
strcpy(msg,"commit");
185193
{ECPGtrans(__LINE__,NULL,"commit");
186-
#line60 "variable.pgc"
194+
#line62 "variable.pgc"
187195

188196
if (sqlca.sqlcode<0)exit (1);}
189-
#line60 "variable.pgc"
197+
#line62 "variable.pgc"
190198

191199

192200
strcpy(msg,"open");
193201
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"declare cur cursor for select name , born , age , married , children from family",ECPGt_EOIT,ECPGt_EORT);
194-
#line63 "variable.pgc"
202+
#line65 "variable.pgc"
195203

196204
if (sqlca.sqlcode<0)exit (1);}
197-
#line63 "variable.pgc"
205+
#line65 "variable.pgc"
198206

199207

200208
/* exec sql whenever not found break ; */
201-
#line65 "variable.pgc"
209+
#line67 "variable.pgc"
202210

203211

204212
p=&personal;
@@ -217,13 +225,13 @@ if (sqlca.sqlcode < 0) exit (1);}
217225
ECPGt_long,&(ind_married),(long)1,(long)1,sizeof(long),
218226
ECPGt_int,&(children.integer),(long)1,(long)1,sizeof(int),
219227
ECPGt_short,&(ind_children.smallint),(long)1,(long)1,sizeof(short),ECPGt_EORT);
220-
#line72 "variable.pgc"
228+
#line74 "variable.pgc"
221229

222230
if (sqlca.sqlcode==ECPG_NOT_FOUND)break;
223-
#line72 "variable.pgc"
231+
#line74 "variable.pgc"
224232

225233
if (sqlca.sqlcode<0)exit (1);}
226-
#line72 "variable.pgc"
234+
#line74 "variable.pgc"
227235

228236
printf("%8.8s",personal.name.arr);
229237
if (i->ind_birth.born >=0)
@@ -242,35 +250,42 @@ if (sqlca.sqlcode < 0) exit (1);}
242250

243251
strcpy(msg,"close");
244252
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"close cur",ECPGt_EOIT,ECPGt_EORT);
245-
#line89 "variable.pgc"
253+
#line91 "variable.pgc"
246254

247255
if (sqlca.sqlcode<0)exit (1);}
248-
#line89 "variable.pgc"
256+
#line91 "variable.pgc"
249257

250258

251259
strcpy(msg,"drop");
252260
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"drop table family",ECPGt_EOIT,ECPGt_EORT);
253-
#line92 "variable.pgc"
261+
#line94 "variable.pgc"
254262

255263
if (sqlca.sqlcode<0)exit (1);}
256-
#line92 "variable.pgc"
264+
#line94 "variable.pgc"
257265

258266

259267
strcpy(msg,"commit");
260268
{ECPGtrans(__LINE__,NULL,"commit");
261-
#line95 "variable.pgc"
269+
#line97 "variable.pgc"
262270

263271
if (sqlca.sqlcode<0)exit (1);}
264-
#line95 "variable.pgc"
272+
#line97 "variable.pgc"
265273

266274

267275
strcpy(msg,"disconnect");
268276
{ECPGdisconnect(__LINE__,"CURRENT");
269-
#line98 "variable.pgc"
277+
#line100 "variable.pgc"
270278

271279
if (sqlca.sqlcode<0)exit (1);}
272-
#line 98 "variable.pgc"
280+
#line 100 "variable.pgc"
281+
273282

283+
/* this just to silence unused-variable warnings: */
284+
vc1.len=vc2.len=vc3.len=0;
285+
i1=i2=i3=0;
286+
printf("%d %d %d %d %d %d\n",
287+
vc1.len,vc2.len,vc3.len,
288+
i1,i2,i3);
274289

275290
return0;
276291
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp