00001
00002
00003 #include <ecpglib.h>
00004 #include <ecpgerrno.h>
00005 #include <sqlca.h>
00006
00007 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00008
00009 #line 1 "variable.pgc"
00010 #include <stdlib.h>
00011 #include <string.h>
00012
00013
00014 #line 1 "regression.h"
00015
00016
00017
00018
00019
00020
00021 #line 4 "variable.pgc"
00022
00023
00024
00025 #line 6 "variable.pgc"
00026
00027
00028
00029 #line 8 "variable.pgc"
00030
00031 typedef char* c;
00032
00033
00034
00035
00036
00037
00038
00039
00040 #line 11 "variable.pgc"
00041
00042 typedef union { int integer; short smallint; } ind;
00043
00044 #define BUFFERSIZ 8
00045
00046 #line 15 "variable.pgc"
00047
00048
00049
00050 #line 18 "variable.pgc"
00051
00052
00053 int
00054 main (void)
00055 {
00056 struct birthinfo {
00057 #line 23 "variable.pgc"
00058 long born ;
00059
00060 #line 23 "variable.pgc"
00061 short age ;
00062 } ;
00063 #line 23 "variable.pgc"
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #line 27 "variable.pgc"
00076 struct personal_struct {
00077 #line 25 "variable.pgc"
00078 struct varchar_1 { int len; char arr[ BUFFERSIZ ]; } name ;
00079
00080 #line 26 "variable.pgc"
00081 struct birthinfo birth ;
00082 } personal , * p ;
00083
00084 #line 30 "variable.pgc"
00085 struct personal_indicator {
00086 #line 28 "variable.pgc"
00087 int ind_name ;
00088
00089 #line 29 "variable.pgc"
00090 struct birthinfo ind_birth ;
00091 } ind_personal , * i ;
00092
00093 #line 31 "variable.pgc"
00094 ind ind_children ;
00095 struct t1 {
00096 #line 32 "variable.pgc"
00097 struct varchar_2 { int len; char arr[ BUFFERSIZ ]; } name ;
00098 } ; struct t2 {
00099 #line 32 "variable.pgc"
00100 struct varchar_3 { int len; char arr[ BUFFERSIZ ]; } name ;
00101 } ;
00102 #line 33 "variable.pgc"
00103
00104
00105
00106 #line 35 "variable.pgc"
00107 char * married = NULL ;
00108
00109 #line 35 "variable.pgc"
00110
00111
00112 #line 36 "variable.pgc"
00113 long ind_married ;
00114
00115 #line 36 "variable.pgc"
00116
00117
00118 #line 37 "variable.pgc"
00119 ind children ;
00120
00121 #line 37 "variable.pgc"
00122
00123
00124 char msg[128];
00125
00126 ECPGdebug(1, stderr);
00127
00128 strcpy(msg, "connect");
00129 { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0);
00130 #line 44 "variable.pgc"
00131
00132 if (sqlca.sqlcode < 0) exit (1);}
00133 #line 44 "variable.pgc"
00134
00135
00136 strcpy(msg, "set");
00137 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
00138 #line 47 "variable.pgc"
00139
00140 if (sqlca.sqlcode < 0) exit (1);}
00141 #line 47 "variable.pgc"
00142
00143
00144 strcpy(msg, "create");
00145 { 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);
00146 #line 50 "variable.pgc"
00147
00148 if (sqlca.sqlcode < 0) exit (1);}
00149 #line 50 "variable.pgc"
00150
00151
00152 strcpy(msg, "insert");
00153 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , married , children ) values ( 'Mum' , '19870714' , 3 )", ECPGt_EOIT, ECPGt_EORT);
00154 #line 53 "variable.pgc"
00155
00156 if (sqlca.sqlcode < 0) exit (1);}
00157 #line 53 "variable.pgc"
00158
00159 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , born , married , children ) values ( 'Dad' , '19610721' , '19870714' , 3 )", ECPGt_EOIT, ECPGt_EORT);
00160 #line 54 "variable.pgc"
00161
00162 if (sqlca.sqlcode < 0) exit (1);}
00163 #line 54 "variable.pgc"
00164
00165 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , age ) values ( 'Child 1' , 16 )", ECPGt_EOIT, ECPGt_EORT);
00166 #line 55 "variable.pgc"
00167
00168 if (sqlca.sqlcode < 0) exit (1);}
00169 #line 55 "variable.pgc"
00170
00171 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , age ) values ( 'Child 2' , 14 )", ECPGt_EOIT, ECPGt_EORT);
00172 #line 56 "variable.pgc"
00173
00174 if (sqlca.sqlcode < 0) exit (1);}
00175 #line 56 "variable.pgc"
00176
00177 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , age ) values ( 'Child 3' , 9 )", ECPGt_EOIT, ECPGt_EORT);
00178 #line 57 "variable.pgc"
00179
00180 if (sqlca.sqlcode < 0) exit (1);}
00181 #line 57 "variable.pgc"
00182
00183
00184 strcpy(msg, "commit");
00185 { ECPGtrans(__LINE__, NULL, "commit");
00186 #line 60 "variable.pgc"
00187
00188 if (sqlca.sqlcode < 0) exit (1);}
00189 #line 60 "variable.pgc"
00190
00191
00192 strcpy(msg, "open");
00193 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select name , born , age , married , children from family", ECPGt_EOIT, ECPGt_EORT);
00194 #line 63 "variable.pgc"
00195
00196 if (sqlca.sqlcode < 0) exit (1);}
00197 #line 63 "variable.pgc"
00198
00199
00200
00201 #line 65 "variable.pgc"
00202
00203
00204 p=&personal;
00205 i=&ind_personal;
00206 memset(i, 0, sizeof(ind_personal));
00207 while (1) {
00208 strcpy(msg, "fetch");
00209 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur", ECPGt_EOIT,
00210 ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)1,sizeof(struct varchar_1),
00211 ECPGt_int,&(i->ind_name),(long)1,(long)1,sizeof(int),
00212 ECPGt_long,&(p->birth.born),(long)1,(long)1,sizeof(long),
00213 ECPGt_long,&(i->ind_birth.born),(long)1,(long)1,sizeof(long),
00214 ECPGt_short,&(p->birth.age),(long)1,(long)1,sizeof(short),
00215 ECPGt_short,&(i->ind_birth.age),(long)1,(long)1,sizeof(short),
00216 ECPGt_char,&(married),(long)0,(long)1,(1)*sizeof(char),
00217 ECPGt_long,&(ind_married),(long)1,(long)1,sizeof(long),
00218 ECPGt_int,&(children.integer),(long)1,(long)1,sizeof(int),
00219 ECPGt_short,&(ind_children.smallint),(long)1,(long)1,sizeof(short), ECPGt_EORT);
00220 #line 72 "variable.pgc"
00221
00222 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
00223 #line 72 "variable.pgc"
00224
00225 if (sqlca.sqlcode < 0) exit (1);}
00226 #line 72 "variable.pgc"
00227
00228 printf("%8.8s", personal.name.arr);
00229 if (i->ind_birth.born >= 0)
00230 printf(", born %ld", personal.birth.born);
00231 if (i->ind_birth.age >= 0)
00232 printf(", age = %d", personal.birth.age);
00233 if (ind_married >= 0)
00234 printf(", married %s", married);
00235 if (ind_children.smallint >= 0)
00236 printf(", children = %d", children.integer);
00237 putchar('\n');
00238
00239 free(married);
00240 married = NULL;
00241 }
00242
00243 strcpy(msg, "close");
00244 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
00245 #line 89 "variable.pgc"
00246
00247 if (sqlca.sqlcode < 0) exit (1);}
00248 #line 89 "variable.pgc"
00249
00250
00251 strcpy(msg, "drop");
00252 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table family", ECPGt_EOIT, ECPGt_EORT);
00253 #line 92 "variable.pgc"
00254
00255 if (sqlca.sqlcode < 0) exit (1);}
00256 #line 92 "variable.pgc"
00257
00258
00259 strcpy(msg, "commit");
00260 { ECPGtrans(__LINE__, NULL, "commit");
00261 #line 95 "variable.pgc"
00262
00263 if (sqlca.sqlcode < 0) exit (1);}
00264 #line 95 "variable.pgc"
00265
00266
00267 strcpy(msg, "disconnect");
00268 { ECPGdisconnect(__LINE__, "CURRENT");
00269 #line 98 "variable.pgc"
00270
00271 if (sqlca.sqlcode < 0) exit (1);}
00272 #line 98 "variable.pgc"
00273
00274
00275 return (0);
00276 }