Header And Logo

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

sql-execute.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 "execute.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 "execute.pgc"
00024 
00025 
00026 /* exec sql whenever sqlerror  sqlprint ; */
00027 #line 8 "execute.pgc"
00028 
00029 
00030 int
00031 main(void)
00032 {
00033 /* exec sql begin declare section */
00034      
00035      
00036      
00037      
00038      
00039 
00040 #line 14 "execute.pgc"
00041  int amount [ 8 ] ;
00042  
00043 #line 15 "execute.pgc"
00044  int increment = 100 ;
00045  
00046 #line 16 "execute.pgc"
00047  char name [ 8 ] [ 8 ] ;
00048  
00049 #line 17 "execute.pgc"
00050  char letter [ 8 ] [ 1 ] ;
00051  
00052 #line 18 "execute.pgc"
00053  char command [ 128 ] ;
00054 /* exec sql end declare section */
00055 #line 19 "execute.pgc"
00056 
00057     int i,j;
00058 
00059     ECPGdebug(1, stderr);
00060 
00061     { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , "main", 0); 
00062 #line 24 "execute.pgc"
00063 
00064 if (sqlca.sqlcode < 0) sqlprint();}
00065 #line 24 "execute.pgc"
00066 
00067     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( name char ( 8 ) , amount int , letter char ( 1 ) )", ECPGt_EOIT, ECPGt_EORT);
00068 #line 25 "execute.pgc"
00069 
00070 if (sqlca.sqlcode < 0) sqlprint();}
00071 #line 25 "execute.pgc"
00072 
00073     { ECPGtrans(__LINE__, NULL, "commit");
00074 #line 26 "execute.pgc"
00075 
00076 if (sqlca.sqlcode < 0) sqlprint();}
00077 #line 26 "execute.pgc"
00078 
00079 
00080     sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
00081     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
00082 #line 29 "execute.pgc"
00083 
00084 if (sqlca.sqlcode < 0) sqlprint();}
00085 #line 29 "execute.pgc"
00086 
00087 
00088     sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
00089     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
00090 #line 32 "execute.pgc"
00091 
00092 if (sqlca.sqlcode < 0) sqlprint();}
00093 #line 32 "execute.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, 0, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
00098 #line 35 "execute.pgc"
00099 
00100 if (sqlca.sqlcode < 0) sqlprint();}
00101 #line 35 "execute.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, 0, "i", command);
00108 #line 40 "execute.pgc"
00109 
00110 if (sqlca.sqlcode < 0) sqlprint();}
00111 #line 40 "execute.pgc"
00112 
00113     { ECPGdo(__LINE__, 0, 1, NULL, 0, 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 "execute.pgc"
00117 
00118 if (sqlca.sqlcode < 0) sqlprint();}
00119 #line 41 "execute.pgc"
00120 
00121 
00122     printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]);
00123 
00124     { ECPGtrans(__LINE__, NULL, "commit");
00125 #line 45 "execute.pgc"
00126 
00127 if (sqlca.sqlcode < 0) sqlprint();}
00128 #line 45 "execute.pgc"
00129 
00130 
00131     sprintf (command, "select * from test");
00132 
00133     { ECPGprepare(__LINE__, NULL, 0, "f", command);
00134 #line 49 "execute.pgc"
00135 
00136 if (sqlca.sqlcode < 0) sqlprint();}
00137 #line 49 "execute.pgc"
00138 
00139     /* declare CUR cursor for $1 */
00140 #line 50 "execute.pgc"
00141 
00142 
00143     { ECPGdo(__LINE__, 0, 1, NULL, 0, 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 "execute.pgc"
00147 
00148 if (sqlca.sqlcode < 0) sqlprint();}
00149 #line 52 "execute.pgc"
00150 
00151     { ECPGdo(__LINE__, 0, 1, NULL, 0, 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 "execute.pgc"
00159 
00160 if (sqlca.sqlcode < 0) sqlprint();}
00161 #line 53 "execute.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 "execute.pgc"
00171  char n [ 8 ] , l = letter [ i ] [ 0 ] ;
00172  
00173 #line 59 "execute.pgc"
00174  int a = amount [ i ] ;
00175 /* exec sql end declare section */
00176 #line 60 "execute.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, 0, ECPGst_normal, "close CUR", ECPGt_EOIT, ECPGt_EORT);
00184 #line 66 "execute.pgc"
00185 
00186 if (sqlca.sqlcode < 0) sqlprint();}
00187 #line 66 "execute.pgc"
00188 
00189     { ECPGdeallocate(__LINE__, 0, NULL, "f");
00190 #line 67 "execute.pgc"
00191 
00192 if (sqlca.sqlcode < 0) sqlprint();}
00193 #line 67 "execute.pgc"
00194 
00195 
00196     sprintf (command, "select * from test where amount = $1");
00197 
00198     { ECPGprepare(__LINE__, NULL, 0, "f", command);
00199 #line 71 "execute.pgc"
00200 
00201 if (sqlca.sqlcode < 0) sqlprint();}
00202 #line 71 "execute.pgc"
00203 
00204     /* declare CUR2 cursor for $1 */
00205 #line 72 "execute.pgc"
00206 
00207 
00208     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare CUR2 cursor for $1", 
00209     ECPGt_char_variable,(ECPGprepared_statement(NULL, "f", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
00210     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00211     ECPGt_const,"1",(long)1,(long)1,strlen("1"), 
00212     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00213 #line 74 "execute.pgc"
00214 
00215 if (sqlca.sqlcode < 0) sqlprint();}
00216 #line 74 "execute.pgc"
00217 
00218     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch in CUR2", ECPGt_EOIT, 
00219     ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char), 
00220     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00221     ECPGt_int,(amount),(long)1,(long)8,sizeof(int), 
00222     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00223     ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char), 
00224     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00225 #line 75 "execute.pgc"
00226 
00227 if (sqlca.sqlcode < 0) sqlprint();}
00228 #line 75 "execute.pgc"
00229 
00230 
00231     for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
00232     {
00233         /* exec sql begin declare section */
00234             
00235            
00236         
00237 #line 80 "execute.pgc"
00238  char n [ 8 ] , l = letter [ i ] [ 0 ] ;
00239  
00240 #line 81 "execute.pgc"
00241  int a = amount [ i ] ;
00242 /* exec sql end declare section */
00243 #line 82 "execute.pgc"
00244 
00245 
00246         strncpy(n, name[i], 8);
00247         printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
00248     }
00249 
00250     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close CUR2", ECPGt_EOIT, ECPGt_EORT);
00251 #line 88 "execute.pgc"
00252 
00253 if (sqlca.sqlcode < 0) sqlprint();}
00254 #line 88 "execute.pgc"
00255 
00256     { ECPGdeallocate(__LINE__, 0, NULL, "f");
00257 #line 89 "execute.pgc"
00258 
00259 if (sqlca.sqlcode < 0) sqlprint();}
00260 #line 89 "execute.pgc"
00261 
00262 
00263     sprintf (command, "select * from test where amount = $1");
00264 
00265     { ECPGprepare(__LINE__, NULL, 0, "f", command);
00266 #line 93 "execute.pgc"
00267 
00268 if (sqlca.sqlcode < 0) sqlprint();}
00269 #line 93 "execute.pgc"
00270 
00271     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "f", 
00272     ECPGt_const,"2",(long)1,(long)1,strlen("2"), 
00273     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
00274     ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char), 
00275     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00276     ECPGt_int,(amount),(long)1,(long)8,sizeof(int), 
00277     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00278     ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char), 
00279     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00280 #line 94 "execute.pgc"
00281 
00282 if (sqlca.sqlcode < 0) sqlprint();}
00283 #line 94 "execute.pgc"
00284 
00285 
00286     for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
00287     {
00288         /* exec sql begin declare section */
00289             
00290            
00291         
00292 #line 99 "execute.pgc"
00293  char n [ 8 ] , l = letter [ i ] [ 0 ] ;
00294  
00295 #line 100 "execute.pgc"
00296  int a = amount [ i ] ;
00297 /* exec sql end declare section */
00298 #line 101 "execute.pgc"
00299 
00300 
00301         strncpy(n, name[i], 8);
00302         printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
00303     }
00304 
00305     { ECPGdeallocate(__LINE__, 0, NULL, "f");
00306 #line 107 "execute.pgc"
00307 
00308 if (sqlca.sqlcode < 0) sqlprint();}
00309 #line 107 "execute.pgc"
00310 
00311     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
00312 #line 108 "execute.pgc"
00313 
00314 if (sqlca.sqlcode < 0) sqlprint();}
00315 #line 108 "execute.pgc"
00316 
00317     { ECPGtrans(__LINE__, NULL, "commit");
00318 #line 109 "execute.pgc"
00319 
00320 if (sqlca.sqlcode < 0) sqlprint();}
00321 #line 109 "execute.pgc"
00322 
00323     { ECPGdisconnect(__LINE__, "CURRENT");
00324 #line 110 "execute.pgc"
00325 
00326 if (sqlca.sqlcode < 0) sqlprint();}
00327 #line 110 "execute.pgc"
00328 
00329 
00330     return (0);
00331 }