Header And Logo

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

compat_informix-test_informix.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 /* Needed for informix compatibility */
00007 #include <ecpg_informix.h>
00008 /* End of automatic include section */
00009 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00010 
00011 #line 1 "test_informix.pgc"
00012 #include "sqltypes.h"
00013 #include <stdlib.h>
00014 
00015 
00016 #line 1 "regression.h"
00017 
00018 
00019 
00020 
00021 
00022 
00023 #line 4 "test_informix.pgc"
00024 
00025 
00026 
00027 static void openit(void);
00028 static void dosqlprint(void) {
00029     printf("doSQLprint: Error: %s\n", sqlca.sqlerrm.sqlerrmc);
00030 }
00031 
00032 int main(void)
00033 {
00034     
00035 #line 14 "test_informix.pgc"
00036  int i = 14 ;
00037 
00038 #line 14 "test_informix.pgc"
00039 
00040     
00041 #line 15 "test_informix.pgc"
00042  decimal j , m , n ;
00043 
00044 #line 15 "test_informix.pgc"
00045 
00046     
00047 #line 16 "test_informix.pgc"
00048  char c [ 10 ] ;
00049 
00050 #line 16 "test_informix.pgc"
00051 
00052 
00053     ECPGdebug(1, stderr);
00054     /* exec sql whenever sqlerror  do dosqlprint ( ) ; */
00055 #line 19 "test_informix.pgc"
00056 
00057 
00058     { ECPGconnect(__LINE__, 1, "regress1" , NULL, NULL , NULL, 0); 
00059 #line 21 "test_informix.pgc"
00060 
00061 if (sqlca.sqlcode < 0) dosqlprint ( );}
00062 #line 21 "test_informix.pgc"
00063 
00064     if (sqlca.sqlcode != 0) exit(1);
00065 
00066     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "create table test ( i int primary key , j int , c text )", ECPGt_EOIT, ECPGt_EORT);
00067 #line 24 "test_informix.pgc"
00068 
00069 if (sqlca.sqlcode < 0) dosqlprint ( );}
00070 #line 24 "test_informix.pgc"
00071 
00072 
00073     /* this INSERT works */
00074     rsetnull(CDECIMALTYPE, (char *)&j);
00075     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( 7 , $1  , 'test   ' )", 
00076     ECPGt_decimal,&(j),(long)1,(long)1,sizeof(decimal), 
00077     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00078 #line 28 "test_informix.pgc"
00079 
00080 if (sqlca.sqlcode < 0) dosqlprint ( );}
00081 #line 28 "test_informix.pgc"
00082 
00083     { ECPGtrans(__LINE__, NULL, "commit");
00084 #line 29 "test_informix.pgc"
00085 
00086 if (sqlca.sqlcode < 0) dosqlprint ( );}
00087 #line 29 "test_informix.pgc"
00088 
00089 
00090     /* this INSERT should fail because i is a unique column */
00091     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( 7 , 12 , 'a' )", ECPGt_EOIT, ECPGt_EORT);
00092 #line 32 "test_informix.pgc"
00093 
00094 if (sqlca.sqlcode < 0) dosqlprint ( );}
00095 #line 32 "test_informix.pgc"
00096 
00097     printf("INSERT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
00098     if (sqlca.sqlcode != 0) { ECPGtrans(__LINE__, NULL, "rollback");
00099 #line 34 "test_informix.pgc"
00100 
00101 if (sqlca.sqlcode < 0) dosqlprint ( );}
00102 #line 34 "test_informix.pgc"
00103 
00104 
00105     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( $1  , 1 , 'a      ' )", 
00106     ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
00107     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00108 #line 36 "test_informix.pgc"
00109 
00110 if (sqlca.sqlcode < 0) dosqlprint ( );}
00111 #line 36 "test_informix.pgc"
00112 
00113     { ECPGtrans(__LINE__, NULL, "commit");
00114 #line 37 "test_informix.pgc"
00115 
00116 if (sqlca.sqlcode < 0) dosqlprint ( );}
00117 #line 37 "test_informix.pgc"
00118 
00119 
00120     /* this will fail (more than one row in subquery) */
00121     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select i from test where j = ( select j from test )", ECPGt_EOIT, ECPGt_EORT);
00122 #line 40 "test_informix.pgc"
00123 
00124 if (sqlca.sqlcode < 0) dosqlprint ( );}
00125 #line 40 "test_informix.pgc"
00126 
00127     { ECPGtrans(__LINE__, NULL, "rollback");
00128 #line 41 "test_informix.pgc"
00129 
00130 if (sqlca.sqlcode < 0) dosqlprint ( );}
00131 #line 41 "test_informix.pgc"
00132 
00133 
00134     /* this however should be ok */
00135     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select i from test where j = ( select j from test order by i limit 1 )", ECPGt_EOIT, ECPGt_EORT);
00136 #line 44 "test_informix.pgc"
00137 
00138 if (sqlca.sqlcode < 0) dosqlprint ( );}
00139 #line 44 "test_informix.pgc"
00140 
00141     printf("SELECT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
00142     if (sqlca.sqlcode != 0) { ECPGtrans(__LINE__, NULL, "rollback");
00143 #line 46 "test_informix.pgc"
00144 
00145 if (sqlca.sqlcode < 0) dosqlprint ( );}
00146 #line 46 "test_informix.pgc"
00147 
00148 
00149     sqlca.sqlcode = 100;
00150     ECPGset_var( 0, &( i ), __LINE__);\
00151  ECPG_informix_reset_sqlca(); /* declare c cursor for select * from test where i <= $1  */
00152 #line 49 "test_informix.pgc"
00153 
00154     printf ("%ld\n", sqlca.sqlcode);
00155     openit();
00156 
00157     deccvint(0, &j);
00158 
00159     while (1)
00160     {
00161         { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch forward c", ECPGt_EOIT, 
00162     ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
00163     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00164     ECPGt_decimal,&(j),(long)1,(long)1,sizeof(decimal), 
00165     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00166     ECPGt_string,(c),(long)10,(long)1,(10)*sizeof(char), 
00167     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00168 #line 57 "test_informix.pgc"
00169 
00170 if (sqlca.sqlcode < 0) dosqlprint ( );}
00171 #line 57 "test_informix.pgc"
00172 
00173         if (sqlca.sqlcode == 100) break;
00174         else if (sqlca.sqlcode != 0) printf ("Error: %ld\n", sqlca.sqlcode);
00175 
00176         if (risnull(CDECIMALTYPE, (char *)&j))
00177             printf("%d NULL\n", i);
00178         else
00179         {
00180             int a;
00181 
00182             dectoint(&j, &a);
00183             printf("%d %d \"%s\"\n", i, a, c);
00184         }
00185     }
00186 
00187     deccvint(7, &j);
00188     deccvint(14, &m);
00189     decadd(&j, &m, &n);
00190     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "delete from test where i = $1  :: decimal", 
00191     ECPGt_decimal,&(n),(long)1,(long)1,sizeof(decimal), 
00192     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00193 #line 75 "test_informix.pgc"
00194 
00195 if (sqlca.sqlcode < 0) dosqlprint ( );}
00196 #line 75 "test_informix.pgc"
00197 
00198     printf("DELETE: %ld\n", sqlca.sqlcode);
00199 
00200     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select 1 from test where i = 14", ECPGt_EOIT, ECPGt_EORT);
00201 #line 78 "test_informix.pgc"
00202 
00203 if (sqlca.sqlcode < 0) dosqlprint ( );}
00204 #line 78 "test_informix.pgc"
00205 
00206     printf("Exists: %ld\n", sqlca.sqlcode);
00207 
00208     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select 1 from test where i = 147", ECPGt_EOIT, ECPGt_EORT);
00209 #line 81 "test_informix.pgc"
00210 
00211 if (sqlca.sqlcode < 0) dosqlprint ( );}
00212 #line 81 "test_informix.pgc"
00213 
00214     printf("Does not exist: %ld\n", sqlca.sqlcode);
00215 
00216     { ECPGtrans(__LINE__, NULL, "commit");
00217 #line 84 "test_informix.pgc"
00218 
00219 if (sqlca.sqlcode < 0) dosqlprint ( );}
00220 #line 84 "test_informix.pgc"
00221 
00222     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
00223 #line 85 "test_informix.pgc"
00224 
00225 if (sqlca.sqlcode < 0) dosqlprint ( );}
00226 #line 85 "test_informix.pgc"
00227 
00228     { ECPGtrans(__LINE__, NULL, "commit");
00229 #line 86 "test_informix.pgc"
00230 
00231 if (sqlca.sqlcode < 0) dosqlprint ( );}
00232 #line 86 "test_informix.pgc"
00233 
00234 
00235     { ECPGdisconnect(__LINE__, "CURRENT");
00236 #line 88 "test_informix.pgc"
00237 
00238 if (sqlca.sqlcode < 0) dosqlprint ( );}
00239 #line 88 "test_informix.pgc"
00240 
00241 
00242     return 0;
00243 }
00244 
00245 static void openit(void)
00246 {
00247     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "declare c cursor for select * from test where i <= $1 ", 
00248     ECPGt_int,&(*( int  *)(ECPGget_var( 0))),(long)1,(long)1,sizeof(int), 
00249     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00250 #line 95 "test_informix.pgc"
00251 
00252 if (sqlca.sqlcode < 0) dosqlprint ( );}
00253 #line 95 "test_informix.pgc"
00254 
00255 }