PostgreSQL Source Code  git master
preproc-pointer_to_struct.c
Go to the documentation of this file.
1 /* Processed by ecpg (regression mode) */
2 /* These include files are added by the preprocessor */
3 #include <ecpglib.h>
4 #include <ecpgerrno.h>
5 #include <sqlca.h>
6 /* End of automatic include section */
7 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8 
9 #line 1 "pointer_to_struct.pgc"
10 #include <stdio.h>
11 #include <stdlib.h>
12 
13 
14 #line 1 "regression.h"
15 
16 
17 
18 
19 
20 
21 #line 4 "pointer_to_struct.pgc"
22 
23 
24 /* exec sql whenever sqlerror sqlprint ; */
25 #line 6 "pointer_to_struct.pgc"
26 
27 /* exec sql whenever sql_warning sqlprint ; */
28 #line 7 "pointer_to_struct.pgc"
29 
30 /* exec sql whenever not found sqlprint ; */
31 #line 8 "pointer_to_struct.pgc"
32 
33 
34 typedef struct {
35 #line 13 "pointer_to_struct.pgc"
36  struct varchar_1 { int len; char arr[ 50 ]; } name ;
37 
38 #line 14 "pointer_to_struct.pgc"
39  int phone ;
40  } customer ;
41 #line 15 "pointer_to_struct.pgc"
42 
43 
44 typedef struct ind {
45 #line 20 "pointer_to_struct.pgc"
46  short name_ind ;
47 
48 #line 21 "pointer_to_struct.pgc"
49  short phone_ind ;
51 #line 22 "pointer_to_struct.pgc"
52 
53 
54 int main()
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 
131 if (sqlca.sqlwarn[0] == 'W') sqlprint();
132 #line 54 "pointer_to_struct.pgc"
133 
134 if (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 
141 if (sqlca.sqlwarn[0] == 'W') sqlprint();
142 #line 56 "pointer_to_struct.pgc"
143 
144 if (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 
150 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
151 #line 57 "pointer_to_struct.pgc"
152 
153 if (sqlca.sqlwarn[0] == 'W') sqlprint();
154 #line 57 "pointer_to_struct.pgc"
155 
156 if (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 
162 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
163 #line 58 "pointer_to_struct.pgc"
164 
165 if (sqlca.sqlwarn[0] == 'W') sqlprint();
166 #line 58 "pointer_to_struct.pgc"
167 
168 if (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 
179 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
180 #line 60 "pointer_to_struct.pgc"
181 
182 if (sqlca.sqlwarn[0] == 'W') sqlprint();
183 #line 60 "pointer_to_struct.pgc"
184 
185 if (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 
202 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
203 #line 68 "pointer_to_struct.pgc"
204 
205 if (sqlca.sqlwarn[0] == 'W') sqlprint();
206 #line 68 "pointer_to_struct.pgc"
207 
208 if (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 
225 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
226 #line 76 "pointer_to_struct.pgc"
227 
228 if (sqlca.sqlwarn[0] == 'W') sqlprint();
229 #line 76 "pointer_to_struct.pgc"
230 
231 if (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 
248 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
249 #line 84 "pointer_to_struct.pgc"
250 
251 if (sqlca.sqlwarn[0] == 'W') sqlprint();
252 #line 84 "pointer_to_struct.pgc"
253 
254 if (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 
266 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
267 #line 89 "pointer_to_struct.pgc"
268 
269 if (sqlca.sqlwarn[0] == 'W') sqlprint();
270 #line 89 "pointer_to_struct.pgc"
271 
272 if (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 
284 if (sqlca.sqlwarn[0] == 'W') sqlprint();
285 #line 96 "pointer_to_struct.pgc"
286 
287 if (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:673
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:2277
#define malloc(a)
Definition: header.h:50
const void size_t len
#define printf(...)
Definition: port.h:244
struct ind cust_ind
#define ECPGdebug(X, Y)
#define sqlca
Definition: sqlca.h:59
struct customer::varchar_1 name
const char * name