Header And Logo

PostgreSQL
| The world's most advanced open source database.

sql-desc.c

Go to the documentation of this file.
00001 /* Processed by ecpg (regression mode) */
00002 /* These include files are added by the preprocessor */
00003 #include <ecpglib.h>
00004 #include <ecpgerrno.h>
00005 #include <sqlca.h>
00006 /* End of automatic include section */
00007 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00008 
00009 #line 1 "desc.pgc"
00010 
00011 #line 1 "regression.h"
00012 
00013 
00014 
00015 
00016 
00017 
00018 #line 1 "desc.pgc"
00019 
00020 /* exec sql whenever sqlerror  sqlprint ; */
00021 #line 2 "desc.pgc"
00022 
00023 
00024 int
00025 main(void)
00026 {
00027     /* exec sql begin declare section */
00028        
00029        
00030        
00031 
00032        
00033           
00034           
00035        
00036       
00037     
00038 #line 8 "desc.pgc"
00039  char * stmt1 = "INSERT INTO test1 VALUES ($1, $2)" ;
00040  
00041 #line 9 "desc.pgc"
00042  char * stmt2 = "SELECT * from test1 where a = $1 and b = $2" ;
00043  
00044 #line 10 "desc.pgc"
00045  char * stmt3 = "SELECT * from test1 where :var = a" ;
00046  
00047 #line 12 "desc.pgc"
00048  int val1 = 1 ;
00049  
00050 #line 13 "desc.pgc"
00051  char val2 [ 4 ] = "one" , val2output [] = "AAA" ;
00052  
00053 #line 14 "desc.pgc"
00054  int val1output = 2 , val2i = 0 ;
00055  
00056 #line 15 "desc.pgc"
00057  int val2null = - 1 ;
00058  
00059 #line 16 "desc.pgc"
00060  int ind1 , ind2 ;
00061 /* exec sql end declare section */
00062 #line 17 "desc.pgc"
00063 
00064 
00065     ECPGdebug(1, stderr);
00066 
00067     ECPGallocate_desc(__LINE__, "indesc");
00068 #line 21 "desc.pgc"
00069 
00070 if (sqlca.sqlcode < 0) sqlprint();
00071 #line 21 "desc.pgc"
00072 
00073     ECPGallocate_desc(__LINE__, "outdesc");
00074 #line 22 "desc.pgc"
00075 
00076 if (sqlca.sqlcode < 0) sqlprint();
00077 #line 22 "desc.pgc"
00078 
00079 
00080     { ECPGset_desc(__LINE__, "indesc", 1,ECPGd_data,
00081     ECPGt_int,&(val1),(long)1,(long)1,sizeof(int), ECPGd_EODT);
00082 
00083 #line 24 "desc.pgc"
00084 
00085 if (sqlca.sqlcode < 0) sqlprint();}
00086 #line 24 "desc.pgc"
00087 
00088     { ECPGset_desc(__LINE__, "indesc", 2,ECPGd_data,
00089     ECPGt_char,(val2),(long)4,(long)1,(4)*sizeof(char), ECPGd_indicator,
00090     ECPGt_int,&(val2i),(long)1,(long)1,sizeof(int), ECPGd_EODT);
00091 
00092 #line 25 "desc.pgc"
00093 
00094 if (sqlca.sqlcode < 0) sqlprint();}
00095 #line 25 "desc.pgc"
00096 
00097 
00098     { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); 
00099 #line 27 "desc.pgc"
00100 
00101 if (sqlca.sqlcode < 0) sqlprint();}
00102 #line 27 "desc.pgc"
00103 
00104 
00105     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test1 ( a int , b text )", ECPGt_EOIT, ECPGt_EORT);
00106 #line 29 "desc.pgc"
00107 
00108 if (sqlca.sqlcode < 0) sqlprint();}
00109 #line 29 "desc.pgc"
00110 
00111     { ECPGprepare(__LINE__, NULL, 0, "foo1", stmt1);
00112 #line 30 "desc.pgc"
00113 
00114 if (sqlca.sqlcode < 0) sqlprint();}
00115 #line 30 "desc.pgc"
00116 
00117     { ECPGprepare(__LINE__, NULL, 0, "Foo-1", stmt1);
00118 #line 31 "desc.pgc"
00119 
00120 if (sqlca.sqlcode < 0) sqlprint();}
00121 #line 31 "desc.pgc"
00122 
00123     { ECPGprepare(__LINE__, NULL, 0, "foo2", stmt2);
00124 #line 32 "desc.pgc"
00125 
00126 if (sqlca.sqlcode < 0) sqlprint();}
00127 #line 32 "desc.pgc"
00128 
00129     { ECPGprepare(__LINE__, NULL, 0, "foo3", stmt3);
00130 #line 33 "desc.pgc"
00131 
00132 if (sqlca.sqlcode < 0) sqlprint();}
00133 #line 33 "desc.pgc"
00134 
00135 
00136     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "foo1", 
00137     ECPGt_descriptor, "indesc", 0L, 0L, 0L, 
00138     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00139 #line 35 "desc.pgc"
00140 
00141 if (sqlca.sqlcode < 0) sqlprint();}
00142 #line 35 "desc.pgc"
00143 
00144 
00145     { ECPGset_desc(__LINE__, "indesc", 1,ECPGd_data,
00146     ECPGt_const,"2",(long)1,(long)1,strlen("2"), ECPGd_EODT);
00147 
00148 #line 37 "desc.pgc"
00149 
00150 if (sqlca.sqlcode < 0) sqlprint();}
00151 #line 37 "desc.pgc"
00152 
00153     { ECPGset_desc(__LINE__, "indesc", 2,ECPGd_data,
00154     ECPGt_char,(val2),(long)4,(long)1,(4)*sizeof(char), ECPGd_indicator,
00155     ECPGt_int,&(val2null),(long)1,(long)1,sizeof(int), ECPGd_EODT);
00156 
00157 #line 38 "desc.pgc"
00158 
00159 if (sqlca.sqlcode < 0) sqlprint();}
00160 #line 38 "desc.pgc"
00161 
00162 
00163     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "foo1", 
00164     ECPGt_descriptor, "indesc", 0L, 0L, 0L, 
00165     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00166 #line 40 "desc.pgc"
00167 
00168 if (sqlca.sqlcode < 0) sqlprint();}
00169 #line 40 "desc.pgc"
00170 
00171 
00172     { ECPGset_desc(__LINE__, "indesc", 1,ECPGd_data,
00173     ECPGt_const,"3",(long)1,(long)1,strlen("3"), ECPGd_EODT);
00174 
00175 #line 42 "desc.pgc"
00176 
00177 if (sqlca.sqlcode < 0) sqlprint();}
00178 #line 42 "desc.pgc"
00179 
00180     { ECPGset_desc(__LINE__, "indesc", 2,ECPGd_data,
00181     ECPGt_const,"this is a long test",(long)19,(long)1,strlen("this is a long test"), ECPGd_indicator,
00182     ECPGt_int,&(val1),(long)1,(long)1,sizeof(int), ECPGd_EODT);
00183 
00184 #line 43 "desc.pgc"
00185 
00186 if (sqlca.sqlcode < 0) sqlprint();}
00187 #line 43 "desc.pgc"
00188 
00189 
00190     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "Foo-1", 
00191     ECPGt_descriptor, "indesc", 0L, 0L, 0L, 
00192     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00193 #line 45 "desc.pgc"
00194 
00195 if (sqlca.sqlcode < 0) sqlprint();}
00196 #line 45 "desc.pgc"
00197 
00198 
00199     { ECPGdeallocate(__LINE__, 0, NULL, "Foo-1");
00200 #line 47 "desc.pgc"
00201 
00202 if (sqlca.sqlcode < 0) sqlprint();}
00203 #line 47 "desc.pgc"
00204 
00205 
00206     { ECPGset_desc(__LINE__, "indesc", 1,ECPGd_data,
00207     ECPGt_int,&(val1),(long)1,(long)1,sizeof(int), ECPGd_EODT);
00208 
00209 #line 49 "desc.pgc"
00210 
00211 if (sqlca.sqlcode < 0) sqlprint();}
00212 #line 49 "desc.pgc"
00213 
00214     { ECPGset_desc(__LINE__, "indesc", 2,ECPGd_data,
00215     ECPGt_char,(val2),(long)4,(long)1,(4)*sizeof(char), ECPGd_indicator,
00216     ECPGt_int,&(val2i),(long)1,(long)1,sizeof(int), ECPGd_EODT);
00217 
00218 #line 50 "desc.pgc"
00219 
00220 if (sqlca.sqlcode < 0) sqlprint();}
00221 #line 50 "desc.pgc"
00222 
00223 
00224     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "foo2", 
00225     ECPGt_descriptor, "indesc", 0L, 0L, 0L, 
00226     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
00227     ECPGt_descriptor, "outdesc", 0L, 0L, 0L, 
00228     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00229 #line 52 "desc.pgc"
00230 
00231 if (sqlca.sqlcode < 0) sqlprint();}
00232 #line 52 "desc.pgc"
00233 
00234 
00235     { ECPGget_desc(__LINE__, "outdesc", 1,ECPGd_data,
00236     ECPGt_char,(val2output),(long)sizeof("AAA"),(long)1,(sizeof("AAA"))*sizeof(char), ECPGd_EODT);
00237 
00238 #line 54 "desc.pgc"
00239 
00240 if (sqlca.sqlcode < 0) sqlprint();}
00241 #line 54 "desc.pgc"
00242 
00243     printf("output = %s\n", val2output);
00244 
00245     /* declare c1 cursor for $1 */
00246 #line 57 "desc.pgc"
00247 
00248     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare c1 cursor for $1", 
00249     ECPGt_char_variable,(ECPGprepared_statement(NULL, "foo2", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
00250     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00251     ECPGt_descriptor, "indesc", 0L, 0L, 0L, 
00252     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00253 #line 58 "desc.pgc"
00254 
00255 if (sqlca.sqlcode < 0) sqlprint();}
00256 #line 58 "desc.pgc"
00257 
00258 
00259     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch next from c1", ECPGt_EOIT, 
00260     ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int), 
00261     ECPGt_int,&(ind1),(long)1,(long)1,sizeof(int), 
00262     ECPGt_char,(val2output),(long)sizeof("AAA"),(long)1,(sizeof("AAA"))*sizeof(char), 
00263     ECPGt_int,&(ind2),(long)1,(long)1,sizeof(int), ECPGt_EORT);
00264 #line 60 "desc.pgc"
00265 
00266 if (sqlca.sqlcode < 0) sqlprint();}
00267 #line 60 "desc.pgc"
00268 
00269     printf("val1=%d (ind1: %d) val2=%s (ind2: %d)\n",
00270         val1output, ind1, val2output, ind2);
00271 
00272     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close c1", ECPGt_EOIT, ECPGt_EORT);
00273 #line 64 "desc.pgc"
00274 
00275 if (sqlca.sqlcode < 0) sqlprint();}
00276 #line 64 "desc.pgc"
00277 
00278 
00279     { ECPGset_desc_header(__LINE__, "indesc", (int)(1));
00280 
00281 #line 66 "desc.pgc"
00282 
00283 if (sqlca.sqlcode < 0) sqlprint();}
00284 #line 66 "desc.pgc"
00285 
00286     { ECPGset_desc(__LINE__, "indesc", 1,ECPGd_data,
00287     ECPGt_const,"2",(long)1,(long)1,strlen("2"), ECPGd_EODT);
00288 
00289 #line 67 "desc.pgc"
00290 
00291 if (sqlca.sqlcode < 0) sqlprint();}
00292 #line 67 "desc.pgc"
00293 
00294 
00295     /* declare c2 cursor for $1 */
00296 #line 69 "desc.pgc"
00297 
00298     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare c2 cursor for $1", 
00299     ECPGt_char_variable,(ECPGprepared_statement(NULL, "foo3", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
00300     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00301     ECPGt_descriptor, "indesc", 0L, 0L, 0L, 
00302     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00303 #line 70 "desc.pgc"
00304 
00305 if (sqlca.sqlcode < 0) sqlprint();}
00306 #line 70 "desc.pgc"
00307 
00308 
00309     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch next from c2", ECPGt_EOIT, 
00310     ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int), 
00311     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00312     ECPGt_char,(val2output),(long)sizeof("AAA"),(long)1,(sizeof("AAA"))*sizeof(char), 
00313     ECPGt_int,&(val2i),(long)1,(long)1,sizeof(int), ECPGt_EORT);
00314 #line 72 "desc.pgc"
00315 
00316 if (sqlca.sqlcode < 0) sqlprint();}
00317 #line 72 "desc.pgc"
00318 
00319     printf("val1=%d val2=%s\n", val1output, val2i ? "null" : val2output);
00320 
00321     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close c2", ECPGt_EOIT, ECPGt_EORT);
00322 #line 75 "desc.pgc"
00323 
00324 if (sqlca.sqlcode < 0) sqlprint();}
00325 #line 75 "desc.pgc"
00326 
00327 
00328     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from test1 where a = 3", ECPGt_EOIT, 
00329     ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int), 
00330     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00331     ECPGt_char,(val2output),(long)sizeof("AAA"),(long)1,(sizeof("AAA"))*sizeof(char), 
00332     ECPGt_int,&(val2i),(long)1,(long)1,sizeof(int), ECPGt_EORT);
00333 #line 77 "desc.pgc"
00334 
00335 if (sqlca.sqlcode < 0) sqlprint();}
00336 #line 77 "desc.pgc"
00337 
00338     printf("val1=%d val2=%c%c%c%c warn=%c truncate=%d\n", val1output, val2output[0], val2output[1], val2output[2], val2output[3], sqlca.sqlwarn[0], val2i);
00339 
00340     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test1", ECPGt_EOIT, ECPGt_EORT);
00341 #line 80 "desc.pgc"
00342 
00343 if (sqlca.sqlcode < 0) sqlprint();}
00344 #line 80 "desc.pgc"
00345 
00346     { ECPGdeallocate_all(__LINE__, 0, NULL);
00347 #line 81 "desc.pgc"
00348 
00349 if (sqlca.sqlcode < 0) sqlprint();}
00350 #line 81 "desc.pgc"
00351 
00352     { ECPGdisconnect(__LINE__, "CURRENT");
00353 #line 82 "desc.pgc"
00354 
00355 if (sqlca.sqlcode < 0) sqlprint();}
00356 #line 82 "desc.pgc"
00357 
00358 
00359     ECPGdeallocate_desc(__LINE__, "indesc");
00360 #line 84 "desc.pgc"
00361 
00362 if (sqlca.sqlcode < 0) sqlprint();
00363 #line 84 "desc.pgc"
00364 
00365     ECPGdeallocate_desc(__LINE__, "outdesc");
00366 #line 85 "desc.pgc"
00367 
00368 if (sqlca.sqlcode < 0) sqlprint();
00369 #line 85 "desc.pgc"
00370 
00371 
00372     return 0;
00373 }