PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
preproc-variable.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 "variable.pgc"
10 #include <stdlib.h>
11 #include <string.h>
12 
13 
14 #line 1 "regression.h"
15 
16 
17 
18 
19 
20 
21 #line 4 "variable.pgc"
22 
23 
24 /* exec sql whenever sqlerror stop ; */
25 #line 6 "variable.pgc"
26 
27 
28 /* exec sql type c is char reference */
29 #line 8 "variable.pgc"
30 
31 typedef char* c;
32 
33 /* exec sql type ind is union {
34 #line 11 "variable.pgc"
35  int integer ;
36 
37 #line 11 "variable.pgc"
38  short smallint ;
39  } */
40 #line 11 "variable.pgc"
41 
42 typedef union { int integer; short smallint; } ind;
43 
44 #define BUFFERSIZ 8
45 /* exec sql type str is [ BUFFERSIZ ] */
46 #line 15 "variable.pgc"
47 
48 
49 /* declare cur cursor for select name , born , age , married , children from family */
50 #line 18 "variable.pgc"
51 
52 
53 int
54 main (void)
55 {
56  struct birthinfo {
57 #line 23 "variable.pgc"
58  long born ;
59 
60 #line 23 "variable.pgc"
61  short age ;
62  } ;
63 #line 23 "variable.pgc"
64 
65 /* exec sql begin declare section */
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 #line 27 "variable.pgc"
78  struct personal_struct {
79 #line 25 "variable.pgc"
80  struct varchar_1 { int len; char arr[ BUFFERSIZ ]; } name ;
81 
82 #line 26 "variable.pgc"
83  struct birthinfo birth ;
84  } personal , * p ;
85 
86 #line 30 "variable.pgc"
87  struct personal_indicator {
88 #line 28 "variable.pgc"
89  int ind_name ;
90 
91 #line 29 "variable.pgc"
92  struct birthinfo ind_birth ;
93  } ind_personal , * i ;
94 
95 #line 31 "variable.pgc"
96  ind ind_children ;
97  struct t1 {
98 #line 32 "variable.pgc"
99  struct varchar_2 { int len; char arr[ BUFFERSIZ ]; } name ;
100  } ; struct t2 {
101 #line 32 "variable.pgc"
102  struct varchar_3 { int len; char arr[ BUFFERSIZ ]; } name ;
103  } ;
104 #line 33 "variable.pgc"
105  static struct varchar_4 { int len; char arr[ 50 ]; } vc1 ; static struct varchar_5 { int len; char arr[ 50 ]; } vc2 ; static struct varchar_6 { int len; char arr[ 255 ]; } vc3 ;
106 
107 #line 34 "variable.pgc"
108  static int i1 , i2 , i3 ;
109 /* exec sql end declare section */
110 #line 35 "variable.pgc"
111 
112 
113 
114 #line 37 "variable.pgc"
115  char * married = NULL ;
116 
117 #line 37 "variable.pgc"
118 
119 
120 #line 38 "variable.pgc"
121  long ind_married ;
122 
123 #line 38 "variable.pgc"
124 
125 
126 #line 39 "variable.pgc"
127  ind children ;
128 
129 #line 39 "variable.pgc"
130 
131  int loopcount;
132  char msg[128];
133 
134  ECPGdebug(1, stderr);
135 
136  strcpy(msg, "connect");
137  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
138 #line 46 "variable.pgc"
139 
140 if (sqlca.sqlcode < 0) exit (1);}
141 #line 46 "variable.pgc"
142 
143 
144  strcpy(msg, "set");
145  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
146 #line 49 "variable.pgc"
147 
148 if (sqlca.sqlcode < 0) exit (1);}
149 #line 49 "variable.pgc"
150 
151 
152  strcpy(msg, "create");
153  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table family ( name char ( 8 ) , born integer , age smallint , married date , children integer )", ECPGt_EOIT, ECPGt_EORT);
154 #line 52 "variable.pgc"
155 
156 if (sqlca.sqlcode < 0) exit (1);}
157 #line 52 "variable.pgc"
158 
159 
160  strcpy(msg, "insert");
161  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , married , children ) values ( 'Mum' , '19870714' , 3 )", ECPGt_EOIT, ECPGt_EORT);
162 #line 55 "variable.pgc"
163 
164 if (sqlca.sqlcode < 0) exit (1);}
165 #line 55 "variable.pgc"
166 
167  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , born , married , children ) values ( 'Dad' , '19610721' , '19870714' , 3 )", ECPGt_EOIT, ECPGt_EORT);
168 #line 56 "variable.pgc"
169 
170 if (sqlca.sqlcode < 0) exit (1);}
171 #line 56 "variable.pgc"
172 
173  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , age ) values ( 'Child 1' , 16 )", ECPGt_EOIT, ECPGt_EORT);
174 #line 57 "variable.pgc"
175 
176 if (sqlca.sqlcode < 0) exit (1);}
177 #line 57 "variable.pgc"
178 
179  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , age ) values ( 'Child 2' , 14 )", ECPGt_EOIT, ECPGt_EORT);
180 #line 58 "variable.pgc"
181 
182 if (sqlca.sqlcode < 0) exit (1);}
183 #line 58 "variable.pgc"
184 
185  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , age ) values ( 'Child 3' , 9 )", ECPGt_EOIT, ECPGt_EORT);
186 #line 59 "variable.pgc"
187 
188 if (sqlca.sqlcode < 0) exit (1);}
189 #line 59 "variable.pgc"
190 
191 
192  strcpy(msg, "commit");
193  { ECPGtrans(__LINE__, NULL, "commit");
194 #line 62 "variable.pgc"
195 
196 if (sqlca.sqlcode < 0) exit (1);}
197 #line 62 "variable.pgc"
198 
199 
200  strcpy(msg, "open");
201  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select name , born , age , married , children from family", ECPGt_EOIT, ECPGt_EORT);
202 #line 65 "variable.pgc"
203 
204 if (sqlca.sqlcode < 0) exit (1);}
205 #line 65 "variable.pgc"
206 
207 
208  /* exec sql whenever not found break ; */
209 #line 67 "variable.pgc"
210 
211 
212  p=&personal;
213  i=&ind_personal;
214  memset(i, 0, sizeof(ind_personal));
215  for (loopcount = 0; loopcount < 100; loopcount++) {
216  strcpy(msg, "fetch");
217  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur", ECPGt_EOIT,
218  ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)-1,sizeof( struct birthinfo ),
219  ECPGt_int,&(i->ind_name),(long)1,(long)-1,sizeof( struct birthinfo ),
220  ECPGt_long,&(p->birth.born),(long)1,(long)1,sizeof( struct birthinfo ),
221  ECPGt_long,&(i->ind_birth.born),(long)1,(long)1,sizeof( struct birthinfo ),
222  ECPGt_short,&(p->birth.age),(long)1,(long)1,sizeof( struct birthinfo ),
223  ECPGt_short,&(i->ind_birth.age),(long)1,(long)1,sizeof( struct birthinfo ),
224  ECPGt_char,&(married),(long)0,(long)1,(1)*sizeof(char),
225  ECPGt_long,&(ind_married),(long)1,(long)1,sizeof(long),
226  ECPGt_int,&(children.integer),(long)1,(long)1,sizeof(int),
227  ECPGt_short,&(ind_children.smallint),(long)1,(long)1,sizeof(short), ECPGt_EORT);
228 #line 74 "variable.pgc"
229 
230 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
231 #line 74 "variable.pgc"
232 
233 if (sqlca.sqlcode < 0) exit (1);}
234 #line 74 "variable.pgc"
235 
236  printf("%8.8s", personal.name.arr);
237  if (i->ind_birth.born >= 0)
238  printf(", born %ld", personal.birth.born);
239  if (i->ind_birth.age >= 0)
240  printf(", age = %d", personal.birth.age);
241  if (ind_married >= 0)
242  printf(", married %s", married);
243  if (ind_children.smallint >= 0)
244  printf(", children = %d", children.integer);
245  putchar('\n');
246 
247  free(married);
248  married = NULL;
249  }
250 
251  strcpy(msg, "close");
252  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
253 #line 91 "variable.pgc"
254 
255 if (sqlca.sqlcode < 0) exit (1);}
256 #line 91 "variable.pgc"
257 
258 
259  strcpy(msg, "drop");
260  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table family", ECPGt_EOIT, ECPGt_EORT);
261 #line 94 "variable.pgc"
262 
263 if (sqlca.sqlcode < 0) exit (1);}
264 #line 94 "variable.pgc"
265 
266 
267  strcpy(msg, "commit");
268  { ECPGtrans(__LINE__, NULL, "commit");
269 #line 97 "variable.pgc"
270 
271 if (sqlca.sqlcode < 0) exit (1);}
272 #line 97 "variable.pgc"
273 
274 
275  strcpy(msg, "disconnect");
276  { ECPGdisconnect(__LINE__, "CURRENT");
277 #line 100 "variable.pgc"
278 
279 if (sqlca.sqlcode < 0) exit (1);}
280 #line 100 "variable.pgc"
281 
282 
283  /* this just to silence unused-variable warnings: */
284  vc1.len = vc2.len = vc3.len = 0;
285  i1 = i2 = i3 = 0;
286  printf("%d %d %d %d %d %d\n",
287  vc1.len, vc2.len, vc3.len,
288  i1, i2, i3);
289 
290  return 0;
291 }
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_long
Definition: ecpgtype.h:44
@ ECPGt_EORT
Definition: ecpgtype.h:63
@ ECPGt_char
Definition: ecpgtype.h:43
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 free(a)
Definition: header.h:65
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:160
int i
Definition: isn.c:72
exit(1)
const void size_t len
#define printf(...)
Definition: port.h:244
int main(void)
#define BUFFERSIZ
char * c
#define ECPGdebug(X, Y)
#define sqlca
Definition: sqlca.h:59
int integer
short smallint
const char * name