PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
preproc-pointer_to_struct.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for preproc-pointer_to_struct.c:

Go to the source code of this file.

Data Structures

struct  customer
 
struct  customer::varchar_1
 
union  ind
 

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-pointer_to_struct.c.

Typedef Documentation

◆ cust_ind

typedef struct ind cust_ind

Function Documentation

◆ main()

int main ( void  )

Definition at line 54 of file preproc-pointer_to_struct.c.

55{
56 /* exec sql begin declare section */
57
58
59
60
61
62
63 typedef struct {
64#line 31 "pointer_to_struct.pgc"
65 struct varchar_2 { int len; char arr[ 50 ]; } name ;
66
67#line 32 "pointer_to_struct.pgc"
68 int phone ;
69 } customer2 ;
70
71#line 33 "pointer_to_struct.pgc"
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90#line 27 "pointer_to_struct.pgc"
91 customer * custs1 = ( customer * ) malloc ( sizeof ( customer ) * 10 ) ;
92
93#line 28 "pointer_to_struct.pgc"
94 cust_ind * inds = ( cust_ind * ) malloc ( sizeof ( cust_ind ) * 10 ) ;
95
96#line 34 "pointer_to_struct.pgc"
97 customer2 * custs2 = ( customer2 * ) malloc ( sizeof ( customer2 ) * 10 ) ;
98
99#line 40 "pointer_to_struct.pgc"
100 struct customer3 {
101#line 38 "pointer_to_struct.pgc"
102 char name [ 50 ] ;
103
104#line 39 "pointer_to_struct.pgc"
105 int phone ;
106 } * custs3 = ( struct customer3 * ) malloc ( sizeof ( struct customer3 ) * 10 ) ;
107
108#line 46 "pointer_to_struct.pgc"
109 struct customer4 {
110#line 44 "pointer_to_struct.pgc"
111 struct varchar_3 { int len; char arr[ 50 ]; } name ;
112
113#line 45 "pointer_to_struct.pgc"
114 int phone ;
115 } * custs4 = ( struct customer4 * ) malloc ( sizeof ( struct customer4 ) ) ;
116
117#line 48 "pointer_to_struct.pgc"
118 int r ;
119
120#line 49 "pointer_to_struct.pgc"
121 struct varchar_4 { int len; char arr[ 50 ]; } onlyname [ 2 ] ;
122/* exec sql end declare section */
123#line 50 "pointer_to_struct.pgc"
124
125
126 ECPGdebug(1, stderr);
127
128 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
129#line 54 "pointer_to_struct.pgc"
130
131if (sqlca.sqlwarn[0] == 'W') sqlprint();
132#line 54 "pointer_to_struct.pgc"
133
134if (sqlca.sqlcode < 0) sqlprint();}
135#line 54 "pointer_to_struct.pgc"
136
137
138 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table customers ( c varchar ( 50 ) , p int )", ECPGt_EOIT, ECPGt_EORT);
139#line 56 "pointer_to_struct.pgc"
140
141if (sqlca.sqlwarn[0] == 'W') sqlprint();
142#line 56 "pointer_to_struct.pgc"
143
144if (sqlca.sqlcode < 0) sqlprint();}
145#line 56 "pointer_to_struct.pgc"
146
147 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into customers values ( 'John Doe' , '12345' )", ECPGt_EOIT, ECPGt_EORT);
148#line 57 "pointer_to_struct.pgc"
149
150if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
151#line 57 "pointer_to_struct.pgc"
152
153if (sqlca.sqlwarn[0] == 'W') sqlprint();
154#line 57 "pointer_to_struct.pgc"
155
156if (sqlca.sqlcode < 0) sqlprint();}
157#line 57 "pointer_to_struct.pgc"
158
159 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into customers values ( 'Jane Doe' , '67890' )", ECPGt_EOIT, ECPGt_EORT);
160#line 58 "pointer_to_struct.pgc"
161
162if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
163#line 58 "pointer_to_struct.pgc"
164
165if (sqlca.sqlwarn[0] == 'W') sqlprint();
166#line 58 "pointer_to_struct.pgc"
167
168if (sqlca.sqlcode < 0) sqlprint();}
169#line 58 "pointer_to_struct.pgc"
170
171
172 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from customers limit 2", ECPGt_EOIT,
173 ECPGt_varchar,&(custs1->name),(long)50,(long)-1,sizeof( customer ),
174 ECPGt_short,&(inds->name_ind),(long)1,(long)-1,sizeof( struct ind ),
175 ECPGt_int,&(custs1->phone),(long)1,(long)-1,sizeof( customer ),
176 ECPGt_short,&(inds->phone_ind),(long)1,(long)-1,sizeof( struct ind ), ECPGt_EORT);
177#line 60 "pointer_to_struct.pgc"
178
179if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
180#line 60 "pointer_to_struct.pgc"
181
182if (sqlca.sqlwarn[0] == 'W') sqlprint();
183#line 60 "pointer_to_struct.pgc"
184
185if (sqlca.sqlcode < 0) sqlprint();}
186#line 60 "pointer_to_struct.pgc"
187
188 printf("custs1:\n");
189 for (r = 0; r < 2; r++)
190 {
191 printf( "name - %s\n", custs1[r].name.arr );
192 printf( "phone - %d\n", custs1[r].phone );
193 }
194
195 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from customers limit 2", ECPGt_EOIT,
196 ECPGt_varchar,&(custs2->name),(long)50,(long)-1,sizeof( customer2 ),
197 ECPGt_short,&(inds->name_ind),(long)1,(long)-1,sizeof( struct ind ),
198 ECPGt_int,&(custs2->phone),(long)1,(long)-1,sizeof( customer2 ),
199 ECPGt_short,&(inds->phone_ind),(long)1,(long)-1,sizeof( struct ind ), ECPGt_EORT);
200#line 68 "pointer_to_struct.pgc"
201
202if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
203#line 68 "pointer_to_struct.pgc"
204
205if (sqlca.sqlwarn[0] == 'W') sqlprint();
206#line 68 "pointer_to_struct.pgc"
207
208if (sqlca.sqlcode < 0) sqlprint();}
209#line 68 "pointer_to_struct.pgc"
210
211 printf("\ncusts2:\n");
212 for (r = 0; r < 2; r++)
213 {
214 printf( "name - %s\n", custs2[r].name.arr );
215 printf( "phone - %d\n", custs2[r].phone );
216 }
217
218 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from customers limit 2", ECPGt_EOIT,
219 ECPGt_char,&(custs3->name),(long)50,(long)-1,sizeof( struct customer3 ),
220 ECPGt_short,&(inds->name_ind),(long)1,(long)-1,sizeof( struct ind ),
221 ECPGt_int,&(custs3->phone),(long)1,(long)-1,sizeof( struct customer3 ),
222 ECPGt_short,&(inds->phone_ind),(long)1,(long)-1,sizeof( struct ind ), ECPGt_EORT);
223#line 76 "pointer_to_struct.pgc"
224
225if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
226#line 76 "pointer_to_struct.pgc"
227
228if (sqlca.sqlwarn[0] == 'W') sqlprint();
229#line 76 "pointer_to_struct.pgc"
230
231if (sqlca.sqlcode < 0) sqlprint();}
232#line 76 "pointer_to_struct.pgc"
233
234 printf("\ncusts3:\n");
235 for (r = 0; r < 2; r++)
236 {
237 printf( "name - %s\n", custs3[r].name );
238 printf( "phone - %d\n", custs3[r].phone );
239 }
240
241 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from customers limit 1", ECPGt_EOIT,
242 ECPGt_varchar,&(custs4->name),(long)50,(long)-1,sizeof( struct customer4 ),
243 ECPGt_short,&(inds->name_ind),(long)1,(long)-1,sizeof( struct ind ),
244 ECPGt_int,&(custs4->phone),(long)1,(long)-1,sizeof( struct customer4 ),
245 ECPGt_short,&(inds->phone_ind),(long)1,(long)-1,sizeof( struct ind ), ECPGt_EORT);
246#line 84 "pointer_to_struct.pgc"
247
248if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
249#line 84 "pointer_to_struct.pgc"
250
251if (sqlca.sqlwarn[0] == 'W') sqlprint();
252#line 84 "pointer_to_struct.pgc"
253
254if (sqlca.sqlcode < 0) sqlprint();}
255#line 84 "pointer_to_struct.pgc"
256
257 printf("\ncusts4:\n");
258 printf( "name - %s\n", custs4->name.arr );
259 printf( "phone - %d\n", custs4->phone );
260
261 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select c from customers limit 2", ECPGt_EOIT,
262 ECPGt_varchar,(onlyname),(long)50,(long)2,sizeof(struct varchar_4),
263 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
264#line 89 "pointer_to_struct.pgc"
265
266if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
267#line 89 "pointer_to_struct.pgc"
268
269if (sqlca.sqlwarn[0] == 'W') sqlprint();
270#line 89 "pointer_to_struct.pgc"
271
272if (sqlca.sqlcode < 0) sqlprint();}
273#line 89 "pointer_to_struct.pgc"
274
275 printf("\nname:\n");
276 for (r = 0; r < 2; r++)
277 {
278 printf( "name - %s\n", onlyname[r].arr );
279 }
280
281 { ECPGdisconnect(__LINE__, "ALL");
282#line 96 "pointer_to_struct.pgc"
283
284if (sqlca.sqlwarn[0] == 'W') sqlprint();
285#line 96 "pointer_to_struct.pgc"
286
287if (sqlca.sqlcode < 0) sqlprint();}
288#line 96 "pointer_to_struct.pgc"
289
290
291 /* All the memory will anyway be freed at the end */
292 return 0;
293}
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:676
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:255
#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
@ ECPGt_char
Definition: ecpgtype.h:43
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:2275
#define malloc(a)
Definition: header.h:50
const void size_t len
#define printf(...)
Definition: port.h:244
#define ECPGdebug(X, Y)
#define sqlca
Definition: sqlca.h:59
struct customer::varchar_1 name
const char * name

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