PostgreSQL Source Code git master
preproc-array_of_struct.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdio.h>
Include dependency graph for preproc-array_of_struct.c:

Go to the source code of this file.

Data Structures

struct  customer
 
struct  customer::varchar_1
 
union  ind
 
struct  company
 

Macros

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 

Typedefs

typedef struct ind cust_ind
 

Functions

int main ()
 

Macro Definition Documentation

◆ ECPGdebug

#define ECPGdebug (   X,
 
)    ECPGdebug((X)+100,(Y))

Definition at line 7 of file preproc-array_of_struct.c.

Typedef Documentation

◆ cust_ind

typedef struct ind cust_ind

Function Documentation

◆ main()

int main ( void  )

Definition at line 60 of file preproc-array_of_struct.c.

61{
62 /* exec sql begin declare section */
63
64
65
66
67
68
69 typedef struct {
70#line 36 "array_of_struct.pgc"
71 struct varchar_2 { int len; char arr[ 50 ]; } name ;
72
73#line 37 "array_of_struct.pgc"
74 int phone ;
75 } customer2 ;
76
77#line 38 "array_of_struct.pgc"
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96#line 32 "array_of_struct.pgc"
97 customer custs1 [ 10 ] ;
98
99#line 33 "array_of_struct.pgc"
100 cust_ind inds [ 10 ] ;
101
102#line 39 "array_of_struct.pgc"
103 customer2 custs2 [ 10 ] ;
104
105#line 44 "array_of_struct.pgc"
106 struct customer3 {
107#line 42 "array_of_struct.pgc"
108 struct varchar_3 { int len; char arr[ 50 ]; } name ;
109
110#line 43 "array_of_struct.pgc"
111 int phone ;
112 } custs3 [ 10 ] ;
113
114#line 49 "array_of_struct.pgc"
115 struct customer4 {
116#line 47 "array_of_struct.pgc"
117 struct varchar_4 { int len; char arr[ 50 ]; } name ;
118
119#line 48 "array_of_struct.pgc"
120 int phone ;
121 } custs4 ;
122
123#line 51 "array_of_struct.pgc"
124 company acme ;
125
126#line 53 "array_of_struct.pgc"
127 int r ;
128
129#line 54 "array_of_struct.pgc"
130 struct varchar_5 { int len; char arr[ 50 ]; } onlyname [ 2 ] ;
131/* exec sql end declare section */
132#line 55 "array_of_struct.pgc"
133
134
135 ECPGdebug(1, stderr);
136
137 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
138#line 59 "array_of_struct.pgc"
139
140if (sqlca.sqlwarn[0] == 'W') sqlprint();
141#line 59 "array_of_struct.pgc"
142
143if (sqlca.sqlcode < 0) sqlprint();}
144#line 59 "array_of_struct.pgc"
145
146
147 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table customers ( c varchar ( 50 ) , p int )", ECPGt_EOIT, ECPGt_EORT);
148#line 61 "array_of_struct.pgc"
149
150if (sqlca.sqlwarn[0] == 'W') sqlprint();
151#line 61 "array_of_struct.pgc"
152
153if (sqlca.sqlcode < 0) sqlprint();}
154#line 61 "array_of_struct.pgc"
155
156
157 /* First we'll insert some data using C variable references */
158 strcpy(custs1[0].name.arr, "John Doe");
159 custs1[0].name.len = strlen(custs1[0].name.arr);
160 custs1[0].phone = 12345;
161
162 strcpy(acme.customers[1].name.arr, "Jane Doe");
163 acme.customers[1].name.len = strlen(acme.customers[1].name.arr);
164 acme.customers[1].phone = 67890;
165
166 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into customers values ( $1 , $2 )",
167 ECPGt_varchar,&(custs1->name),(long)50,(long)1,sizeof(struct varchar_1),
168 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
169 ECPGt_int,&(custs1[0].phone),(long)1,(long)1,sizeof(int),
170 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
171#line 73 "array_of_struct.pgc"
172
173if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
174#line 73 "array_of_struct.pgc"
175
176if (sqlca.sqlwarn[0] == 'W') sqlprint();
177#line 73 "array_of_struct.pgc"
178
179if (sqlca.sqlcode < 0) sqlprint();}
180#line 73 "array_of_struct.pgc"
181
182 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into customers values ( $1 , $2 )",
183 ECPGt_varchar,&(acme.customers[1].name),(long)50,(long)1,sizeof(struct varchar_1),
184 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
185 ECPGt_int,&(acme.customers[1].phone),(long)1,(long)1,sizeof(int),
186 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
187#line 75 "array_of_struct.pgc"
188
189if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
190#line 75 "array_of_struct.pgc"
191
192if (sqlca.sqlwarn[0] == 'W') sqlprint();
193#line 75 "array_of_struct.pgc"
194
195if (sqlca.sqlcode < 0) sqlprint();}
196#line 75 "array_of_struct.pgc"
197
198
199 /* Clear the array, to be sure reading back into it actually gets data */
200 memset(custs1, 0, sizeof(customer) * 10);
201
202 /* Now read back the data */
203 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from customers limit 2", ECPGt_EOIT,
204 ECPGt_varchar,&(custs1->name),(long)50,(long)10,sizeof( customer ),
205 ECPGt_short,&(inds->name_ind),(long)1,(long)10,sizeof( struct ind ),
206 ECPGt_int,&(custs1->phone),(long)1,(long)10,sizeof( customer ),
207 ECPGt_short,&(inds->phone_ind),(long)1,(long)10,sizeof( struct ind ), ECPGt_EORT);
208#line 81 "array_of_struct.pgc"
209
210if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
211#line 81 "array_of_struct.pgc"
212
213if (sqlca.sqlwarn[0] == 'W') sqlprint();
214#line 81 "array_of_struct.pgc"
215
216if (sqlca.sqlcode < 0) sqlprint();}
217#line 81 "array_of_struct.pgc"
218
219 printf("custs1:\n");
220 for (r = 0; r < 2; r++)
221 {
222 printf( "name - %s\n", custs1[r].name.arr );
223 printf( "phone - %d\n", custs1[r].phone );
224 }
225
226 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from customers limit 2", ECPGt_EOIT,
227 ECPGt_varchar,&(custs2->name),(long)50,(long)10,sizeof( customer2 ),
228 ECPGt_short,&(inds->name_ind),(long)1,(long)10,sizeof( struct ind ),
229 ECPGt_int,&(custs2->phone),(long)1,(long)10,sizeof( customer2 ),
230 ECPGt_short,&(inds->phone_ind),(long)1,(long)10,sizeof( struct ind ), ECPGt_EORT);
231#line 89 "array_of_struct.pgc"
232
233if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
234#line 89 "array_of_struct.pgc"
235
236if (sqlca.sqlwarn[0] == 'W') sqlprint();
237#line 89 "array_of_struct.pgc"
238
239if (sqlca.sqlcode < 0) sqlprint();}
240#line 89 "array_of_struct.pgc"
241
242 printf("\ncusts2:\n");
243 for (r = 0; r < 2; r++)
244 {
245 printf( "name - %s\n", custs2[r].name.arr );
246 printf( "phone - %d\n", custs2[r].phone );
247 }
248
249 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from customers limit 2", ECPGt_EOIT,
250 ECPGt_varchar,&(custs3->name),(long)50,(long)10,sizeof( struct customer3 ),
251 ECPGt_short,&(inds->name_ind),(long)1,(long)10,sizeof( struct ind ),
252 ECPGt_int,&(custs3->phone),(long)1,(long)10,sizeof( struct customer3 ),
253 ECPGt_short,&(inds->phone_ind),(long)1,(long)10,sizeof( struct ind ), ECPGt_EORT);
254#line 97 "array_of_struct.pgc"
255
256if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
257#line 97 "array_of_struct.pgc"
258
259if (sqlca.sqlwarn[0] == 'W') sqlprint();
260#line 97 "array_of_struct.pgc"
261
262if (sqlca.sqlcode < 0) sqlprint();}
263#line 97 "array_of_struct.pgc"
264
265 printf("\ncusts3:\n");
266 for (r = 0; r < 2; r++)
267 {
268 printf( "name - %s\n", custs3[r].name.arr );
269 printf( "phone - %d\n", custs3[r].phone );
270 }
271
272 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from customers limit 1", ECPGt_EOIT,
273 ECPGt_varchar,&(custs4.name),(long)50,(long)1,sizeof( struct customer4 ),
274 ECPGt_short,&(inds[0].name_ind),(long)1,(long)1,sizeof( struct ind ),
275 ECPGt_int,&(custs4.phone),(long)1,(long)1,sizeof( struct customer4 ),
276 ECPGt_short,&(inds[0].phone_ind),(long)1,(long)1,sizeof( struct ind ), ECPGt_EORT);
277#line 105 "array_of_struct.pgc"
278
279if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
280#line 105 "array_of_struct.pgc"
281
282if (sqlca.sqlwarn[0] == 'W') sqlprint();
283#line 105 "array_of_struct.pgc"
284
285if (sqlca.sqlcode < 0) sqlprint();}
286#line 105 "array_of_struct.pgc"
287
288 printf("\ncusts4:\n");
289 printf( "name - %s\n", custs4.name.arr );
290 printf( "phone - %d\n", custs4.phone );
291
292 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select c from customers limit 2", ECPGt_EOIT,
293 ECPGt_varchar,(onlyname),(long)50,(long)2,sizeof(struct varchar_5),
294 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
295#line 110 "array_of_struct.pgc"
296
297if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
298#line 110 "array_of_struct.pgc"
299
300if (sqlca.sqlwarn[0] == 'W') sqlprint();
301#line 110 "array_of_struct.pgc"
302
303if (sqlca.sqlcode < 0) sqlprint();}
304#line 110 "array_of_struct.pgc"
305
306 printf("\nname:\n");
307 for (r = 0; r < 2; r++)
308 {
309 printf( "name - %s\n", onlyname[r].arr );
310 }
311
312 { ECPGdisconnect(__LINE__, "ALL");
313#line 117 "array_of_struct.pgc"
314
315if (sqlca.sqlwarn[0] == 'W') sqlprint();
316#line 117 "array_of_struct.pgc"
317
318if (sqlca.sqlcode < 0) sqlprint();}
319#line 117 "array_of_struct.pgc"
320
321
322 return 0;
323}
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:693
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:260
#define ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_short
Definition: ecpgtype.h:43
@ ECPGt_varchar
Definition: ecpgtype.h:48
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
void sqlprint(void)
Definition: error.c:334
bool ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query,...)
Definition: execute.c:2291
const void size_t len
#define printf(...)
Definition: port.h:266
#define ECPGdebug(X, Y)
#define sqlca
Definition: sqlca.h:59
customer customers[10]
struct customer::varchar_1 name
const char * name

References customer::varchar_1::arr, company::customers, ECPG_NOT_FOUND, ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGst_normal, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, ECPGt_short, ECPGt_varchar, customer::varchar_1::len, len, name, customer::name, ind::name_ind, customer::phone, ind::phone_ind, printf, sqlca, and sqlprint().