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
 

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.

Referenced by main().

Typedef Documentation

◆ cust_ind

Function Documentation

◆ main()

int main ( void  )

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

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

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