Skip to content

Commit fb7b1df

Browse files
author
Michael Meskes
committed
Fixed bug that caused arrays of varchar to be output with incomplete name.
In the process expanded one test case,
1 parent 0f855d6 commit fb7b1df

File tree

6 files changed

+122
-71
lines changed

6 files changed

+122
-71
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,3 +2322,8 @@ Sun, 17 Feb 2008 18:45:39 +0100
23222322
- Removed duplicate include of ecpgtype.h.
23232323
- Changed INFORMIX mode symbol definition yet again because the old
23242324
way didn't work on NetBSD.
2325+
2326+
Sun, 02 Mar 2008 11:50:48 +0100
2327+
2328+
- Fixed bug that caused arrays of varchar to be output with incomplete
2329+
name.

src/interfaces/ecpg/preproc/type.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.c,v 1.77 2007/12/21 14:33:20 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.c,v 1.78 2008/03/02 10:54:11 meskes Exp $ */
22

33
#include "postgres_fe.h"
44

@@ -259,7 +259,7 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type,
259259

260260
ECPGdump_a_simple(o, name,
261261
type->u.element->type,
262-
type->u.element->size, type->size, NULL, prefix, type->lineno);
262+
type->u.element->size, type->size, NULL, prefix, type->u.element->lineno);
263263

264264
if (ind_type != NULL)
265265
{

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

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ int main( int argc, char * argv[] )
8181

8282

8383

84+
8485

8586
#line 26 "array_of_struct.pgc"
8687
customer custs1 [ 10 ] ;
@@ -111,71 +112,74 @@ int main( int argc, char * argv[] )
111112

112113
#line 44 "array_of_struct.pgc"
113114
int r ;
114-
/* exec sql end declare section */
115+
115116
#line 45 "array_of_struct.pgc"
117+
struct varchar_onlyname_45 { int len; char arr[ 50 ]; } onlyname [2] ;
118+
/* exec sql end declare section */
119+
#line 46 "array_of_struct.pgc"
116120

117121

118122
ECPGdebug(1, stderr);
119123

120124
{ ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0);
121-
#line 49 "array_of_struct.pgc"
125+
#line 50 "array_of_struct.pgc"
122126

123127
if (sqlca.sqlwarn[0] == 'W') sqlprint();
124-
#line 49 "array_of_struct.pgc"
128+
#line 50 "array_of_struct.pgc"
125129

126130
if (sqlca.sqlcode < 0) sqlprint();}
127-
#line 49 "array_of_struct.pgc"
131+
#line 50 "array_of_struct.pgc"
128132

129133

130134
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table customers ( c varchar ( 50 ) , p int ) ", ECPGt_EOIT, ECPGt_EORT);
131-
#line 51 "array_of_struct.pgc"
135+
#line 52 "array_of_struct.pgc"
132136

133137
if (sqlca.sqlwarn[0] == 'W') sqlprint();
134-
#line 51 "array_of_struct.pgc"
138+
#line 52 "array_of_struct.pgc"
135139

136140
if (sqlca.sqlcode < 0) sqlprint();}
137-
#line 51 "array_of_struct.pgc"
141+
#line 52 "array_of_struct.pgc"
138142

139143
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into customers values ( 'John Doe' , '12345' ) ", ECPGt_EOIT, ECPGt_EORT);
140-
#line 52 "array_of_struct.pgc"
144+
#line 53 "array_of_struct.pgc"
141145

142146
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
143-
#line 52 "array_of_struct.pgc"
147+
#line 53 "array_of_struct.pgc"
144148

145149
if (sqlca.sqlwarn[0] == 'W') sqlprint();
146-
#line 52 "array_of_struct.pgc"
150+
#line 53 "array_of_struct.pgc"
147151

148152
if (sqlca.sqlcode < 0) sqlprint();}
149-
#line 52 "array_of_struct.pgc"
153+
#line 53 "array_of_struct.pgc"
150154

151155
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into customers values ( 'Jane Doe' , '67890' ) ", ECPGt_EOIT, ECPGt_EORT);
152-
#line 53 "array_of_struct.pgc"
156+
#line 54 "array_of_struct.pgc"
153157

154158
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
155-
#line 53 "array_of_struct.pgc"
159+
#line 54 "array_of_struct.pgc"
156160

157161
if (sqlca.sqlwarn[0] == 'W') sqlprint();
158-
#line 53 "array_of_struct.pgc"
162+
#line 54 "array_of_struct.pgc"
159163

160164
if (sqlca.sqlcode < 0) sqlprint();}
161-
#line 53 "array_of_struct.pgc"
165+
#line 54 "array_of_struct.pgc"
162166

163167

164168
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from customers limit 2 ", ECPGt_EOIT,
165169
ECPGt_varchar,&(custs1->name),(long)50,(long)10,sizeof( customer ),
166170
ECPGt_short,&(inds->name_ind),(long)1,(long)10,sizeof( struct ind ),
167171
ECPGt_int,&(custs1->phone),(long)1,(long)10,sizeof( customer ),
168172
ECPGt_short,&(inds->phone_ind),(long)1,(long)10,sizeof( struct ind ), ECPGt_EORT);
169-
#line 55 "array_of_struct.pgc"
173+
#line 56 "array_of_struct.pgc"
170174

171175
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
172-
#line 55 "array_of_struct.pgc"
176+
#line 56 "array_of_struct.pgc"
173177

174178
if (sqlca.sqlwarn[0] == 'W') sqlprint();
175-
#line 55 "array_of_struct.pgc"
179+
#line 56 "array_of_struct.pgc"
176180

177181
if (sqlca.sqlcode < 0) sqlprint();}
178-
#line 55 "array_of_struct.pgc"
182+
#line 56 "array_of_struct.pgc"
179183

180184
printf("custs1:\n");
181185
for (r = 0; r < 2; r++)
@@ -189,16 +193,16 @@ if (sqlca.sqlcode < 0) sqlprint();}
189193
ECPGt_short,&(inds->name_ind),(long)1,(long)10,sizeof( struct ind ),
190194
ECPGt_int,&(custs2->phone),(long)1,(long)10,sizeof( customer2 ),
191195
ECPGt_short,&(inds->phone_ind),(long)1,(long)10,sizeof( struct ind ), ECPGt_EORT);
192-
#line 63 "array_of_struct.pgc"
196+
#line 64 "array_of_struct.pgc"
193197

194198
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
195-
#line 63 "array_of_struct.pgc"
199+
#line 64 "array_of_struct.pgc"
196200

197201
if (sqlca.sqlwarn[0] == 'W') sqlprint();
198-
#line 63 "array_of_struct.pgc"
202+
#line 64 "array_of_struct.pgc"
199203

200204
if (sqlca.sqlcode < 0) sqlprint();}
201-
#line 63 "array_of_struct.pgc"
205+
#line 64 "array_of_struct.pgc"
202206

203207
printf("\ncusts2:\n");
204208
for (r = 0; r < 2; r++)
@@ -212,16 +216,16 @@ if (sqlca.sqlcode < 0) sqlprint();}
212216
ECPGt_short,&(inds->name_ind),(long)1,(long)10,sizeof( struct ind ),
213217
ECPGt_int,&(custs3->phone),(long)1,(long)10,sizeof( struct customer3 ),
214218
ECPGt_short,&(inds->phone_ind),(long)1,(long)10,sizeof( struct ind ), ECPGt_EORT);
215-
#line 71 "array_of_struct.pgc"
219+
#line 72 "array_of_struct.pgc"
216220

217221
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
218-
#line 71 "array_of_struct.pgc"
222+
#line 72 "array_of_struct.pgc"
219223

220224
if (sqlca.sqlwarn[0] == 'W') sqlprint();
221-
#line 71 "array_of_struct.pgc"
225+
#line 72 "array_of_struct.pgc"
222226

223227
if (sqlca.sqlcode < 0) sqlprint();}
224-
#line 71 "array_of_struct.pgc"
228+
#line 72 "array_of_struct.pgc"
225229

226230
printf("\ncusts3:\n");
227231
for (r = 0; r < 2; r++)
@@ -235,29 +239,49 @@ if (sqlca.sqlcode < 0) sqlprint();}
235239
ECPGt_short,&(inds[0].name_ind),(long)1,(long)1,sizeof(short),
236240
ECPGt_int,&(custs4.phone),(long)1,(long)1,sizeof(int),
237241
ECPGt_short,&(inds[0].phone_ind),(long)1,(long)1,sizeof(short), ECPGt_EORT);
238-
#line 79 "array_of_struct.pgc"
242+
#line 80 "array_of_struct.pgc"
239243

240244
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
241-
#line 79 "array_of_struct.pgc"
245+
#line 80 "array_of_struct.pgc"
242246

243247
if (sqlca.sqlwarn[0] == 'W') sqlprint();
244-
#line 79 "array_of_struct.pgc"
248+
#line 80 "array_of_struct.pgc"
245249

246250
if (sqlca.sqlcode < 0) sqlprint();}
247-
#line 79 "array_of_struct.pgc"
251+
#line 80 "array_of_struct.pgc"
248252

249253
printf("\ncusts4:\n");
250254
printf( "name - %s\n", custs4.name.arr );
251255
printf( "phone - %d\n", custs4.phone );
252256

257+
{ 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_45),
259+
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
260+
#line 85 "array_of_struct.pgc"
261+
262+
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
263+
#line 85 "array_of_struct.pgc"
264+
265+
if (sqlca.sqlwarn[0] == 'W') sqlprint();
266+
#line 85 "array_of_struct.pgc"
267+
268+
if (sqlca.sqlcode < 0) sqlprint();}
269+
#line 85 "array_of_struct.pgc"
270+
271+
printf("\nname:\n");
272+
for (r = 0; r < 2; r++)
273+
{
274+
printf( "name - %s\n", onlyname[r].arr );
275+
}
276+
253277
{ ECPGdisconnect(__LINE__, "ALL");
254-
#line 84 "array_of_struct.pgc"
278+
#line 92 "array_of_struct.pgc"
255279

256280
if (sqlca.sqlwarn[0] == 'W') sqlprint();
257-
#line 84 "array_of_struct.pgc"
281+
#line 92 "array_of_struct.pgc"
258282

259283
if (sqlca.sqlcode < 0) sqlprint();}
260-
#line 84 "array_of_struct.pgc"
284+
#line 92 "array_of_struct.pgc"
261285

262286

263287
return( 0 );

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

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,75 +2,85 @@
22
[NO_PID]: sqlca: code: 0, state: 00000
33
[NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT>
44
[NO_PID]: sqlca: code: 0, state: 00000
5-
[NO_PID]: ecpg_execute line 51: QUERY: create table customers ( c varchar ( 50 ) , p int ) with 0 parameter on connection regress1
6-
[NO_PID]: sqlca: code: 0, state: 00000
7-
[NO_PID]: ecpg_execute line 51: using PQexec
8-
[NO_PID]: sqlca: code: 0, state: 00000
9-
[NO_PID]: ecpg_execute line 51 Ok: CREATE TABLE
10-
[NO_PID]: sqlca: code: 0, state: 00000
11-
[NO_PID]: ecpg_execute line 52: QUERY: insert into customers values ( 'John Doe' , '12345' ) with 0 parameter on connection regress1
5+
[NO_PID]: ecpg_execute line 52: QUERY: create table customers ( c varchar ( 50 ) , p int ) with 0 parameter on connection regress1
126
[NO_PID]: sqlca: code: 0, state: 00000
137
[NO_PID]: ecpg_execute line 52: using PQexec
148
[NO_PID]: sqlca: code: 0, state: 00000
15-
[NO_PID]: ecpg_execute line 52 Ok: INSERT 0 1
9+
[NO_PID]: ecpg_execute line 52 Ok: CREATE TABLE
1610
[NO_PID]: sqlca: code: 0, state: 00000
17-
[NO_PID]: ecpg_execute line 53: QUERY: insert into customers values ( 'Jane Doe' , '67890' ) with 0 parameter on connection regress1
11+
[NO_PID]: ecpg_execute line 53: QUERY: insert into customers values ( 'John Doe' , '12345' ) with 0 parameter on connection regress1
1812
[NO_PID]: sqlca: code: 0, state: 00000
1913
[NO_PID]: ecpg_execute line 53: using PQexec
2014
[NO_PID]: sqlca: code: 0, state: 00000
2115
[NO_PID]: ecpg_execute line 53 Ok: INSERT 0 1
2216
[NO_PID]: sqlca: code: 0, state: 00000
23-
[NO_PID]: ecpg_execute line 55: QUERY: select * from customers limit 2 with 0 parameter on connection regress1
17+
[NO_PID]: ecpg_execute line 54: QUERY: insert into customers values ( 'Jane Doe' , '67890' ) with 0 parameter on connection regress1
18+
[NO_PID]: sqlca: code: 0, state: 00000
19+
[NO_PID]: ecpg_execute line 54: using PQexec
20+
[NO_PID]: sqlca: code: 0, state: 00000
21+
[NO_PID]: ecpg_execute line 54 Ok: INSERT 0 1
22+
[NO_PID]: sqlca: code: 0, state: 00000
23+
[NO_PID]: ecpg_execute line 56: QUERY: select * from customers limit 2 with 0 parameter on connection regress1
24+
[NO_PID]: sqlca: code: 0, state: 00000
25+
[NO_PID]: ecpg_execute line 56: using PQexec
26+
[NO_PID]: sqlca: code: 0, state: 00000
27+
[NO_PID]: ecpg_execute line 56: Correctly got 2 tuples with 2 fields
28+
[NO_PID]: sqlca: code: 0, state: 00000
29+
[NO_PID]: ecpg_get_data line 56: RESULT: John Doe offset: -1 array: Yes
30+
[NO_PID]: sqlca: code: 0, state: 00000
31+
[NO_PID]: ecpg_get_data line 56: RESULT: Jane Doe offset: -1 array: Yes
32+
[NO_PID]: sqlca: code: 0, state: 00000
33+
[NO_PID]: ecpg_get_data line 56: RESULT: 12345 offset: -1 array: Yes
2434
[NO_PID]: sqlca: code: 0, state: 00000
25-
[NO_PID]: ecpg_execute line 55: using PQexec
35+
[NO_PID]: ecpg_get_data line 56: RESULT: 67890 offset: -1 array: Yes
2636
[NO_PID]: sqlca: code: 0, state: 00000
27-
[NO_PID]: ecpg_execute line 55: Correctly got 2 tuples with 2 fields
37+
[NO_PID]: ecpg_execute line 64: QUERY: select * from customers limit 2 with 0 parameter on connection regress1
2838
[NO_PID]: sqlca: code: 0, state: 00000
29-
[NO_PID]: ecpg_get_data line 55: RESULT: John Doe offset: -1 array: Yes
39+
[NO_PID]: ecpg_execute line 64: using PQexec
3040
[NO_PID]: sqlca: code: 0, state: 00000
31-
[NO_PID]: ecpg_get_data line 55: RESULT: Jane Doe offset: -1 array: Yes
41+
[NO_PID]: ecpg_execute line 64: Correctly got 2 tuples with 2 fields
3242
[NO_PID]: sqlca: code: 0, state: 00000
33-
[NO_PID]: ecpg_get_data line 55: RESULT: 12345 offset: -1 array: Yes
43+
[NO_PID]: ecpg_get_data line 64: RESULT: John Doe offset: -1 array: Yes
3444
[NO_PID]: sqlca: code: 0, state: 00000
35-
[NO_PID]: ecpg_get_data line 55: RESULT: 67890 offset: -1 array: Yes
45+
[NO_PID]: ecpg_get_data line 64: RESULT: Jane Doe offset: -1 array: Yes
3646
[NO_PID]: sqlca: code: 0, state: 00000
37-
[NO_PID]: ecpg_execute line 63: QUERY: select * from customers limit 2 with 0 parameter on connection regress1
47+
[NO_PID]: ecpg_get_data line 64: RESULT: 12345 offset: -1 array: Yes
3848
[NO_PID]: sqlca: code: 0, state: 00000
39-
[NO_PID]: ecpg_execute line 63: using PQexec
49+
[NO_PID]: ecpg_get_data line 64: RESULT: 67890 offset: -1 array: Yes
4050
[NO_PID]: sqlca: code: 0, state: 00000
41-
[NO_PID]: ecpg_execute line 63: Correctly got 2 tuples with 2 fields
51+
[NO_PID]: ecpg_execute line 72: QUERY: select * from customers limit 2 with 0 parameter on connection regress1
4252
[NO_PID]: sqlca: code: 0, state: 00000
43-
[NO_PID]: ecpg_get_data line 63: RESULT: John Doe offset: -1 array: Yes
53+
[NO_PID]: ecpg_execute line 72: using PQexec
4454
[NO_PID]: sqlca: code: 0, state: 00000
45-
[NO_PID]: ecpg_get_data line 63: RESULT: Jane Doe offset: -1 array: Yes
55+
[NO_PID]: ecpg_execute line 72: Correctly got 2 tuples with 2 fields
4656
[NO_PID]: sqlca: code: 0, state: 00000
47-
[NO_PID]: ecpg_get_data line 63: RESULT: 12345 offset: -1 array: Yes
57+
[NO_PID]: ecpg_get_data line 72: RESULT: John Doe offset: -1 array: Yes
4858
[NO_PID]: sqlca: code: 0, state: 00000
49-
[NO_PID]: ecpg_get_data line 63: RESULT: 67890 offset: -1 array: Yes
59+
[NO_PID]: ecpg_get_data line 72: RESULT: Jane Doe offset: -1 array: Yes
5060
[NO_PID]: sqlca: code: 0, state: 00000
51-
[NO_PID]: ecpg_execute line 71: QUERY: select * from customers limit 2 with 0 parameter on connection regress1
61+
[NO_PID]: ecpg_get_data line 72: RESULT: 12345 offset: -1 array: Yes
5262
[NO_PID]: sqlca: code: 0, state: 00000
53-
[NO_PID]: ecpg_execute line 71: using PQexec
63+
[NO_PID]: ecpg_get_data line 72: RESULT: 67890 offset: -1 array: Yes
5464
[NO_PID]: sqlca: code: 0, state: 00000
55-
[NO_PID]: ecpg_execute line 71: Correctly got 2 tuples with 2 fields
65+
[NO_PID]: ecpg_execute line 80: QUERY: select * from customers limit 1 with 0 parameter on connection regress1
5666
[NO_PID]: sqlca: code: 0, state: 00000
57-
[NO_PID]: ecpg_get_data line 71: RESULT: John Doe offset: -1 array: Yes
67+
[NO_PID]: ecpg_execute line 80: using PQexec
5868
[NO_PID]: sqlca: code: 0, state: 00000
59-
[NO_PID]: ecpg_get_data line 71: RESULT: Jane Doe offset: -1 array: Yes
69+
[NO_PID]: ecpg_execute line 80: Correctly got 1 tuples with 2 fields
6070
[NO_PID]: sqlca: code: 0, state: 00000
61-
[NO_PID]: ecpg_get_data line 71: RESULT: 12345 offset: -1 array: Yes
71+
[NO_PID]: ecpg_get_data line 80: RESULT: John Doe offset: -1 array: Yes
6272
[NO_PID]: sqlca: code: 0, state: 00000
63-
[NO_PID]: ecpg_get_data line 71: RESULT: 67890 offset: -1 array: Yes
73+
[NO_PID]: ecpg_get_data line 80: RESULT: 12345 offset: -1 array: Yes
6474
[NO_PID]: sqlca: code: 0, state: 00000
65-
[NO_PID]: ecpg_execute line 79: QUERY: select * from customers limit 1 with 0 parameter on connection regress1
75+
[NO_PID]: ecpg_execute line 85: QUERY: select c from customers limit 2 with 0 parameter on connection regress1
6676
[NO_PID]: sqlca: code: 0, state: 00000
67-
[NO_PID]: ecpg_execute line 79: using PQexec
77+
[NO_PID]: ecpg_execute line 85: using PQexec
6878
[NO_PID]: sqlca: code: 0, state: 00000
69-
[NO_PID]: ecpg_execute line 79: Correctly got 1 tuples with 2 fields
79+
[NO_PID]: ecpg_execute line 85: Correctly got 2 tuples with 1 fields
7080
[NO_PID]: sqlca: code: 0, state: 00000
71-
[NO_PID]: ecpg_get_data line 79: RESULT: John Doe offset: -1 array: Yes
81+
[NO_PID]: ecpg_get_data line 85: RESULT: John Doe offset: -1 array: Yes
7282
[NO_PID]: sqlca: code: 0, state: 00000
73-
[NO_PID]: ecpg_get_data line 79: RESULT: 12345 offset: -1 array: Yes
83+
[NO_PID]: ecpg_get_data line 85: RESULT: Jane Doe offset: -1 array: Yes
7484
[NO_PID]: sqlca: code: 0, state: 00000
7585
[NO_PID]: ecpg_finish: Connection regress1 closed.
7686
[NO_PID]: sqlca: code: 0, state: 00000

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ phone - 67890
1919
custs4:
2020
name - John Doe
2121
phone - 12345
22+
23+
name:
24+
name - John Doe
25+
name - Jane Doe

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ int main( int argc, char * argv[] )
4242
int phone;
4343
} custs4;
4444
int r;
45+
varchar onlyname[2][50];
4546
EXEC SQL end declare section;
4647

4748
ECPGdebug(1, stderr);
@@ -81,6 +82,13 @@ int main( int argc, char * argv[] )
8182
printf( "name - %s\n", custs4.name.arr );
8283
printf( "phone - %d\n", custs4.phone );
8384

85+
EXEC SQL select c INTO :onlyname from customers limit 2;
86+
printf("\nname:\n");
87+
for (r = 0; r < 2; r++)
88+
{
89+
printf( "name - %s\n", onlyname[r].arr );
90+
}
91+
8492
EXEC SQL disconnect all;
8593

8694
return( 0 );

0 commit comments

Comments
 (0)