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