Header And Logo

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

sql-oldexec.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 "oldexec.pgc"
00010 #include <stdlib.h>
00011 #include <string.h>
00012 #include <stdlib.h>
00013 #include <stdio.h>
00014 
00015 
00016 #line 1 "regression.h"
00017 
00018 
00019 
00020 
00021 
00022 
00023 #line 6 "oldexec.pgc"
00024 
00025 
00026 /* exec sql whenever sqlerror  sqlprint ; */
00027 #line 8 "oldexec.pgc"
00028 
00029 
00030 int
00031 main(void)
00032 {
00033 /* exec sql begin declare section */
00034      
00035      
00036      
00037      
00038      
00039 
00040 #line 14 "oldexec.pgc"
00041  int amount [ 8 ] ;
00042  
00043 #line 15 "oldexec.pgc"
00044  int increment = 100 ;
00045  
00046 #line 16 "oldexec.pgc"
00047  char name [ 8 ] [ 8 ] ;
00048  
00049 #line 17 "oldexec.pgc"
00050  char letter [ 8 ] [ 1 ] ;
00051  
00052 #line 18 "oldexec.pgc"
00053  char command [ 128 ] ;
00054 /* exec sql end declare section */
00055 #line 19 "oldexec.pgc"
00056 
00057     int i,j;
00058 
00059     ECPGdebug(1, stderr);
00060 
00061     { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , "main", 0); 
00062 #line 24 "oldexec.pgc"
00063 
00064 if (sqlca.sqlcode < 0) sqlprint();}
00065 #line 24 "oldexec.pgc"
00066 
00067     { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "create table test ( name char ( 8 ) , amount int , letter char ( 1 ) )", ECPGt_EOIT, ECPGt_EORT);
00068 #line 25 "oldexec.pgc"
00069 
00070 if (sqlca.sqlcode < 0) sqlprint();}
00071 #line 25 "oldexec.pgc"
00072 
00073     { ECPGtrans(__LINE__, NULL, "commit");
00074 #line 26 "oldexec.pgc"
00075 
00076 if (sqlca.sqlcode < 0) sqlprint();}
00077 #line 26 "oldexec.pgc"
00078 
00079 
00080     sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
00081     { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
00082 #line 29 "oldexec.pgc"
00083 
00084 if (sqlca.sqlcode < 0) sqlprint();}
00085 #line 29 "oldexec.pgc"
00086 
00087 
00088     sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
00089     { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
00090 #line 32 "oldexec.pgc"
00091 
00092 if (sqlca.sqlcode < 0) sqlprint();}
00093 #line 32 "oldexec.pgc"
00094 
00095 
00096     sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test");
00097     { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
00098 #line 35 "oldexec.pgc"
00099 
00100 if (sqlca.sqlcode < 0) sqlprint();}
00101 #line 35 "oldexec.pgc"
00102 
00103 
00104     printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]);
00105 
00106     sprintf(command, "insert into test (name, amount, letter) select name, amount+$1, letter from test");
00107     { ECPGprepare(__LINE__, NULL, 1, "i", command);
00108 #line 40 "oldexec.pgc"
00109 
00110 if (sqlca.sqlcode < 0) sqlprint();}
00111 #line 40 "oldexec.pgc"
00112 
00113     { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_execute, "i", 
00114     ECPGt_int,&(increment),(long)1,(long)1,sizeof(int), 
00115     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00116 #line 41 "oldexec.pgc"
00117 
00118 if (sqlca.sqlcode < 0) sqlprint();}
00119 #line 41 "oldexec.pgc"
00120 
00121 
00122     printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]);
00123 
00124     { ECPGtrans(__LINE__, NULL, "commit");
00125 #line 45 "oldexec.pgc"
00126 
00127 if (sqlca.sqlcode < 0) sqlprint();}
00128 #line 45 "oldexec.pgc"
00129 
00130 
00131     sprintf (command, "select * from test");
00132 
00133     { ECPGprepare(__LINE__, NULL, 1, "f", command);
00134 #line 49 "oldexec.pgc"
00135 
00136 if (sqlca.sqlcode < 0) sqlprint();}
00137 #line 49 "oldexec.pgc"
00138 
00139     /* declare CUR cursor for $1 */
00140 #line 50 "oldexec.pgc"
00141 
00142 
00143     { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "declare CUR cursor for $1", 
00144     ECPGt_char_variable,(ECPGprepared_statement(NULL, "f", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
00145     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00146 #line 52 "oldexec.pgc"
00147 
00148 if (sqlca.sqlcode < 0) sqlprint();}
00149 #line 52 "oldexec.pgc"
00150 
00151     { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "fetch 8 in CUR", ECPGt_EOIT, 
00152     ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char), 
00153     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00154     ECPGt_int,(amount),(long)1,(long)8,sizeof(int), 
00155     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00156     ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char), 
00157     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00158 #line 53 "oldexec.pgc"
00159 
00160 if (sqlca.sqlcode < 0) sqlprint();}
00161 #line 53 "oldexec.pgc"
00162 
00163 
00164     for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
00165     {
00166         /* exec sql begin declare section */
00167             
00168            
00169         
00170 #line 58 "oldexec.pgc"
00171  char n [ 8 ] , l = letter [ i ] [ 0 ] ;
00172  
00173 #line 59 "oldexec.pgc"
00174  int a = amount [ i ] ;
00175 /* exec sql end declare section */
00176 #line 60 "oldexec.pgc"
00177 
00178 
00179         strncpy(n, name[i], 8);
00180         printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
00181     }
00182 
00183     { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "close CUR", ECPGt_EOIT, ECPGt_EORT);
00184 #line 66 "oldexec.pgc"
00185 
00186 if (sqlca.sqlcode < 0) sqlprint();}
00187 #line 66 "oldexec.pgc"
00188 
00189 
00190     sprintf (command, "select * from test where ? = amount");
00191 
00192     { ECPGprepare(__LINE__, NULL, 1, "f", command);
00193 #line 70 "oldexec.pgc"
00194 
00195 if (sqlca.sqlcode < 0) sqlprint();}
00196 #line 70 "oldexec.pgc"
00197 
00198     /* declare CUR3 cursor for $1 */
00199 #line 71 "oldexec.pgc"
00200 
00201 
00202     { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "declare CUR3 cursor for $1", 
00203     ECPGt_char_variable,(ECPGprepared_statement(NULL, "f", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
00204     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00205     ECPGt_const,"1",(long)1,(long)1,strlen("1"), 
00206     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00207 #line 73 "oldexec.pgc"
00208 
00209 if (sqlca.sqlcode < 0) sqlprint();}
00210 #line 73 "oldexec.pgc"
00211 
00212     { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "fetch in CUR3", ECPGt_EOIT, 
00213     ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char), 
00214     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00215     ECPGt_int,(amount),(long)1,(long)8,sizeof(int), 
00216     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00217     ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char), 
00218     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00219 #line 74 "oldexec.pgc"
00220 
00221 if (sqlca.sqlcode < 0) sqlprint();}
00222 #line 74 "oldexec.pgc"
00223 
00224 
00225     for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
00226     {
00227         /* exec sql begin declare section */
00228             
00229            
00230         
00231 #line 79 "oldexec.pgc"
00232  char n [ 8 ] , l = letter [ i ] [ 0 ] ;
00233  
00234 #line 80 "oldexec.pgc"
00235  int a = amount [ i ] ;
00236 /* exec sql end declare section */
00237 #line 81 "oldexec.pgc"
00238 
00239 
00240         strncpy(n, name[i], 8);
00241         printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
00242     }
00243 
00244     { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "close CUR3", ECPGt_EOIT, ECPGt_EORT);
00245 #line 87 "oldexec.pgc"
00246 
00247 if (sqlca.sqlcode < 0) sqlprint();}
00248 #line 87 "oldexec.pgc"
00249 
00250     { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
00251 #line 88 "oldexec.pgc"
00252 
00253 if (sqlca.sqlcode < 0) sqlprint();}
00254 #line 88 "oldexec.pgc"
00255 
00256     { ECPGtrans(__LINE__, NULL, "commit");
00257 #line 89 "oldexec.pgc"
00258 
00259 if (sqlca.sqlcode < 0) sqlprint();}
00260 #line 89 "oldexec.pgc"
00261 
00262     { ECPGdisconnect(__LINE__, "CURRENT");
00263 #line 90 "oldexec.pgc"
00264 
00265 if (sqlca.sqlcode < 0) sqlprint();}
00266 #line 90 "oldexec.pgc"
00267 
00268 
00269     return (0);
00270 }