Header And Logo

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

preproc-autoprep.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 "autoprep.pgc"
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <string.h>
00013 
00014 /* test automatic prepare for all statements */
00015 
00016 #line 1 "regression.h"
00017 
00018 
00019 
00020 
00021 
00022 
00023 #line 6 "autoprep.pgc"
00024 
00025 
00026 static void test(void) {
00027   /* exec sql begin declare section */
00028          
00029       
00030        
00031   
00032 #line 10 "autoprep.pgc"
00033  int item [ 4 ] , ind [ 4 ] , i = 1 ;
00034  
00035 #line 11 "autoprep.pgc"
00036  int item1 , ind1 ;
00037  
00038 #line 12 "autoprep.pgc"
00039  char sqlstr [ 64 ] = "SELECT item2 FROM T ORDER BY item2 NULLS LAST" ;
00040 /* exec sql end declare section */
00041 #line 13 "autoprep.pgc"
00042 
00043 
00044   ECPGdebug(1, stderr);
00045   { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
00046 #line 16 "autoprep.pgc"
00047 
00048 
00049   /* exec sql whenever sql_warning  sqlprint ; */
00050 #line 18 "autoprep.pgc"
00051 
00052   /* exec sql whenever sqlerror  sqlprint ; */
00053 #line 19 "autoprep.pgc"
00054 
00055 
00056   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table T ( Item1 int , Item2 int )", ECPGt_EOIT, ECPGt_EORT);
00057 #line 21 "autoprep.pgc"
00058 
00059 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00060 #line 21 "autoprep.pgc"
00061 
00062 if (sqlca.sqlcode < 0) sqlprint();}
00063 #line 21 "autoprep.pgc"
00064 
00065 
00066   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_prepnormal, "insert into T values ( 1 , null )", ECPGt_EOIT, ECPGt_EORT);
00067 #line 23 "autoprep.pgc"
00068 
00069 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00070 #line 23 "autoprep.pgc"
00071 
00072 if (sqlca.sqlcode < 0) sqlprint();}
00073 #line 23 "autoprep.pgc"
00074 
00075   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_prepnormal, "insert into T values ( 1 , $1  )", 
00076     ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
00077     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00078 #line 24 "autoprep.pgc"
00079 
00080 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00081 #line 24 "autoprep.pgc"
00082 
00083 if (sqlca.sqlcode < 0) sqlprint();}
00084 #line 24 "autoprep.pgc"
00085 
00086   i++;
00087   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_prepnormal, "insert into T values ( 1 , $1  )", 
00088     ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
00089     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00090 #line 26 "autoprep.pgc"
00091 
00092 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00093 #line 26 "autoprep.pgc"
00094 
00095 if (sqlca.sqlcode < 0) sqlprint();}
00096 #line 26 "autoprep.pgc"
00097 
00098   { ECPGprepare(__LINE__, NULL, 0, "i", " insert into T values ( 1 , 2 ) ");
00099 #line 27 "autoprep.pgc"
00100 
00101 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00102 #line 27 "autoprep.pgc"
00103 
00104 if (sqlca.sqlcode < 0) sqlprint();}
00105 #line 27 "autoprep.pgc"
00106 
00107   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "i", ECPGt_EOIT, ECPGt_EORT);
00108 #line 28 "autoprep.pgc"
00109 
00110 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00111 #line 28 "autoprep.pgc"
00112 
00113 if (sqlca.sqlcode < 0) sqlprint();}
00114 #line 28 "autoprep.pgc"
00115 
00116 
00117   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_prepnormal, "select Item2 from T order by Item2 nulls last", ECPGt_EOIT, 
00118     ECPGt_int,(item),(long)1,(long)4,sizeof(int), 
00119     ECPGt_int,(ind),(long)1,(long)4,sizeof(int), ECPGt_EORT);
00120 #line 30 "autoprep.pgc"
00121 
00122 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00123 #line 30 "autoprep.pgc"
00124 
00125 if (sqlca.sqlcode < 0) sqlprint();}
00126 #line 30 "autoprep.pgc"
00127 
00128 
00129   for (i=0; i<4; i++)
00130     printf("item[%d] = %d\n", i, ind[i] ? -1 : item[i]);
00131 
00132   /* declare C cursor for select Item1 from T */
00133 #line 35 "autoprep.pgc"
00134 
00135 
00136   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare C cursor for select Item1 from T", ECPGt_EOIT, ECPGt_EORT);
00137 #line 37 "autoprep.pgc"
00138 
00139 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00140 #line 37 "autoprep.pgc"
00141 
00142 if (sqlca.sqlcode < 0) sqlprint();}
00143 #line 37 "autoprep.pgc"
00144 
00145 
00146   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 in C", ECPGt_EOIT, 
00147     ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
00148     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00149 #line 39 "autoprep.pgc"
00150 
00151 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00152 #line 39 "autoprep.pgc"
00153 
00154 if (sqlca.sqlcode < 0) sqlprint();}
00155 #line 39 "autoprep.pgc"
00156 
00157   printf("i = %d\n", i);
00158 
00159   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);
00160 #line 42 "autoprep.pgc"
00161 
00162 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00163 #line 42 "autoprep.pgc"
00164 
00165 if (sqlca.sqlcode < 0) sqlprint();}
00166 #line 42 "autoprep.pgc"
00167 
00168 
00169   { ECPGprepare(__LINE__, NULL, 0, "stmt1", sqlstr);
00170 #line 44 "autoprep.pgc"
00171 
00172 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00173 #line 44 "autoprep.pgc"
00174 
00175 if (sqlca.sqlcode < 0) sqlprint();}
00176 #line 44 "autoprep.pgc"
00177 
00178 
00179   /* declare cur1 cursor for $1 */
00180 #line 46 "autoprep.pgc"
00181 
00182 
00183   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur1 cursor for $1", 
00184     ECPGt_char_variable,(ECPGprepared_statement(NULL, "stmt1", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
00185     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00186 #line 48 "autoprep.pgc"
00187 
00188 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00189 #line 48 "autoprep.pgc"
00190 
00191 if (sqlca.sqlcode < 0) sqlprint();}
00192 #line 48 "autoprep.pgc"
00193 
00194 
00195   /* exec sql whenever not found  break ; */
00196 #line 50 "autoprep.pgc"
00197 
00198 
00199   i = 0;
00200   while (1)
00201   {
00202     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur1", ECPGt_EOIT, 
00203     ECPGt_int,&(item1),(long)1,(long)1,sizeof(int), 
00204     ECPGt_int,&(ind1),(long)1,(long)1,sizeof(int), ECPGt_EORT);
00205 #line 55 "autoprep.pgc"
00206 
00207 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
00208 #line 55 "autoprep.pgc"
00209 
00210 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00211 #line 55 "autoprep.pgc"
00212 
00213 if (sqlca.sqlcode < 0) sqlprint();}
00214 #line 55 "autoprep.pgc"
00215 
00216     printf("item[%d] = %d\n", i, ind1 ? -1 : item1);
00217     i++;
00218   }
00219 
00220   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur1", ECPGt_EOIT, ECPGt_EORT);
00221 #line 60 "autoprep.pgc"
00222 
00223 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00224 #line 60 "autoprep.pgc"
00225 
00226 if (sqlca.sqlcode < 0) sqlprint();}
00227 #line 60 "autoprep.pgc"
00228 
00229 
00230   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table T", ECPGt_EOIT, ECPGt_EORT);
00231 #line 62 "autoprep.pgc"
00232 
00233 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00234 #line 62 "autoprep.pgc"
00235 
00236 if (sqlca.sqlcode < 0) sqlprint();}
00237 #line 62 "autoprep.pgc"
00238 
00239 
00240   { ECPGdisconnect(__LINE__, "ALL");
00241 #line 64 "autoprep.pgc"
00242 
00243 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00244 #line 64 "autoprep.pgc"
00245 
00246 if (sqlca.sqlcode < 0) sqlprint();}
00247 #line 64 "autoprep.pgc"
00248 
00249 }
00250 
00251 int main() {
00252   test();
00253   test();     /* retry */
00254 
00255   return 0;
00256 }