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
main(void)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 #line 27 "variable.pgc"
76 struct personal_struct {
77 #line 25 "variable.pgc"
78 struct varchar_1 { int len; char arr[ BUFFERSIZ ]; } name ;
79
80 #line 26 "variable.pgc"
81 struct birthinfo birth ;
82 } personal , * p ;
83
84 #line 30 "variable.pgc"
85 struct personal_indicator {
86 #line 28 "variable.pgc"
87 int ind_name ;
88
89 #line 29 "variable.pgc"
90 struct birthinfo ind_birth ;
91 } ind_personal , * i ;
92
93 #line 31 "variable.pgc"
94 ind ind_children ;
95 struct t1 {
96 #line 32 "variable.pgc"
97 struct varchar_2 { int len; char arr[ BUFFERSIZ ]; } name ;
98 } ; struct t2 {
99 #line 32 "variable.pgc"
100 struct varchar_3 { int len; char arr[ BUFFERSIZ ]; } name ;
101 } ;/* exec sql end declare section */
102 #line 33 "variable.pgc"
103
104
105
106 #line 35 "variable.pgc"
107 char * married = NULL ;
108
109 #line 35 "variable.pgc"
110
111
112 #line 36 "variable.pgc"
113 long ind_married ;
114
115 #line 36 "variable.pgc"
116
117
118 #line 37 "variable.pgc"
119 ind children ;
120
121 #line 37 "variable.pgc"
122
123 int loopcount;
124 char msg[128];
125
126 ECPGdebug(1, stderr);
127
128 strcpy(msg, "connect");
129 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
130 #line 44 "variable.pgc"
131
132 if (sqlca.sqlcode < 0) exit (1);}
133 #line 44 "variable.pgc"
134
135
136 strcpy(msg, "set");
137 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
138 #line 47 "variable.pgc"
139
140 if (sqlca.sqlcode < 0) exit (1);}
141 #line 47 "variable.pgc"
142
143
144 strcpy(msg, "create");
145 { 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);
146 #line 50 "variable.pgc"
147
148 if (sqlca.sqlcode < 0) exit (1);}
149 #line 50 "variable.pgc"
150
151
152 strcpy(msg, "insert");
153 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , married , children ) values ( 'Mum' , '19870714' , 3 )", ECPGt_EOIT, ECPGt_EORT);
154 #line 53 "variable.pgc"
155
156 if (sqlca.sqlcode < 0) exit (1);}
157 #line 53 "variable.pgc"
158
159 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , born , married , children ) values ( 'Dad' , '19610721' , '19870714' , 3 )", ECPGt_EOIT, ECPGt_EORT);
160 #line 54 "variable.pgc"
161
162 if (sqlca.sqlcode < 0) exit (1);}
163 #line 54 "variable.pgc"
164
165 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , age ) values ( 'Child 1' , 16 )", ECPGt_EOIT, ECPGt_EORT);
166 #line 55 "variable.pgc"
167
168 if (sqlca.sqlcode < 0) exit (1);}
169 #line 55 "variable.pgc"
170
171 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , age ) values ( 'Child 2' , 14 )", ECPGt_EOIT, ECPGt_EORT);
172 #line 56 "variable.pgc"
173
174 if (sqlca.sqlcode < 0) exit (1);}
175 #line 56 "variable.pgc"
176
177 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , age ) values ( 'Child 3' , 9 )", ECPGt_EOIT, ECPGt_EORT);
178 #line 57 "variable.pgc"
179
180 if (sqlca.sqlcode < 0) exit (1);}
181 #line 57 "variable.pgc"
182
183
184 strcpy(msg, "commit");
185 { ECPGtrans(__LINE__, NULL, "commit");
186 #line 60 "variable.pgc"
187
188 if (sqlca.sqlcode < 0) exit (1);}
189 #line 60 "variable.pgc"
190
191
192 strcpy(msg, "open");
193 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select name , born , age , married , children from family", ECPGt_EOIT, ECPGt_EORT);
194 #line 63 "variable.pgc"
195
196 if (sqlca.sqlcode < 0) exit (1);}
197 #line 63 "variable.pgc"
198
199
200 /* exec sql whenever not found break ; */
201 #line 65 "variable.pgc"
202
203
204 p=&personal;
205 i=&ind_personal;
206 memset(i, 0, sizeof(ind_personal));
207 for (loopcount = 0; loopcount < 100; loopcount++) {
208 strcpy(msg, "fetch");
209 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur", ECPGt_EOIT,
210 ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)-1,sizeof( struct birthinfo ),
211 ECPGt_int,&(i->ind_name),(long)1,(long)-1,sizeof( struct birthinfo ),
212 ECPGt_long,&(p->birth.born),(long)1,(long)1,sizeof( struct birthinfo ),
213 ECPGt_long,&(i->ind_birth.born),(long)1,(long)1,sizeof( struct birthinfo ),
214 ECPGt_short,&(p->birth.age),(long)1,(long)1,sizeof( struct birthinfo ),
215 ECPGt_short,&(i->ind_birth.age),(long)1,(long)1,sizeof( struct birthinfo ),
216 ECPGt_char,&(married),(long)0,(long)1,(1)*sizeof(char),
217 ECPGt_long,&(ind_married),(long)1,(long)1,sizeof(long),
218 ECPGt_int,&(children.integer),(long)1,(long)1,sizeof(int),
219 ECPGt_short,&(ind_children.smallint),(long)1,(long)1,sizeof(short), ECPGt_EORT);
220 #line 72 "variable.pgc"
221
222 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
223 #line 72 "variable.pgc"
224
225 if (sqlca.sqlcode < 0) exit (1);}
226 #line 72 "variable.pgc"
227
228 printf("%8.8s", personal.name.arr);
229 if (i->ind_birth.born >= 0)
230 printf(", born %ld", personal.birth.born);
231 if (i->ind_birth.age >= 0)
232 printf(", age = %d", personal.birth.age);
233 if (ind_married >= 0)
234 printf(", married %s", married);
235 if (ind_children.smallint >= 0)
236 printf(", children = %d", children.integer);
237 putchar('\n');
238
239 free(married);
240 married = NULL;
241 }
242
243 strcpy(msg, "close");
244 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
245 #line 89 "variable.pgc"
246
247 if (sqlca.sqlcode < 0) exit (1);}
248 #line 89 "variable.pgc"
249
250
251 strcpy(msg, "drop");
252 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table family", ECPGt_EOIT, ECPGt_EORT);
253 #line 92 "variable.pgc"
254
255 if (sqlca.sqlcode < 0) exit (1);}
256 #line 92 "variable.pgc"
257
258
259 strcpy(msg, "commit");
260 { ECPGtrans(__LINE__, NULL, "commit");
261 #line 95 "variable.pgc"
262
263 if (sqlca.sqlcode < 0) exit (1);}
264 #line 95 "variable.pgc"
265
266
267 strcpy(msg, "disconnect");
268 { ECPGdisconnect(__LINE__, "CURRENT");
269 #line 98 "variable.pgc"
270
271 if (sqlca.sqlcode < 0) exit (1);}
272 #line 98 "variable.pgc"
273
274
275 return 0;
276 }
277