00001
00002
00003 #include <ecpglib.h>
00004 #include <ecpgerrno.h>
00005 #include <sqlca.h>
00006
00007 #include <ecpg_informix.h>
00008
00009 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00010
00011 #line 1 "test_informix2.pgc"
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 #include "sqltypes.h"
00015
00016
00017 #line 1 "sqlca.h"
00018 #ifndef POSTGRES_SQLCA_H
00019 #define POSTGRES_SQLCA_H
00020
00021 #ifndef PGDLLIMPORT
00022 #if defined(WIN32) || defined(__CYGWIN__)
00023 #define PGDLLIMPORT __declspec (dllimport)
00024 #else
00025 #define PGDLLIMPORT
00026 #endif
00027 #endif
00028
00029 #define SQLERRMC_LEN 150
00030
00031 #ifdef __cplusplus
00032 extern "C"
00033 {
00034 #endif
00035
00036 struct sqlca_t
00037 {
00038 char sqlcaid[8];
00039 long sqlabc;
00040 long sqlcode;
00041 struct
00042 {
00043 int sqlerrml;
00044 char sqlerrmc[SQLERRMC_LEN];
00045 } sqlerrm;
00046 char sqlerrp[8];
00047 long sqlerrd[6];
00048
00049
00050
00051
00052
00053
00054
00055
00056 char sqlwarn[8];
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 char sqlstate[5];
00071 };
00072
00073 struct sqlca_t *ECPGget_sqlca(void);
00074
00075 #ifndef POSTGRES_ECPG_INTERNAL
00076 #define sqlca (*ECPGget_sqlca())
00077 #endif
00078
00079 #ifdef __cplusplus
00080 }
00081 #endif
00082
00083 #endif
00084
00085 #line 5 "test_informix2.pgc"
00086
00087
00088 #line 1 "regression.h"
00089
00090
00091
00092
00093
00094
00095 #line 6 "test_informix2.pgc"
00096
00097
00098
00099
00100 static void sql_check(char *fn, char *caller, int ignore)
00101 {
00102 char errorstring[255];
00103
00104 if (SQLCODE == ignore)
00105 return;
00106 else
00107 {
00108 if (SQLCODE != 0)
00109 {
00110
00111 sprintf(errorstring, "**SQL error %ld doing '%s' in function '%s'. [%s]",
00112 SQLCODE, caller, fn, sqlca.sqlerrm.sqlerrmc);
00113 fprintf(stderr, "%s", errorstring);
00114 printf("%s\n", errorstring);
00115
00116
00117 { ECPGtrans(__LINE__, NULL, "rollback");}
00118 #line 27 "test_informix2.pgc"
00119
00120
00121 if (SQLCODE == 0)
00122 {
00123 sprintf(errorstring, "Rollback successful.\n");
00124 } else {
00125 sprintf(errorstring, "Rollback failed with code %ld.\n", SQLCODE);
00126 }
00127
00128 fprintf(stderr, "%s", errorstring);
00129 printf("%s\n", errorstring);
00130
00131 exit(1);
00132 }
00133 }
00134 }
00135
00136
00137
00138 int main(void)
00139 {
00140
00141
00142
00143
00144
00145
00146
00147 #line 49 "test_informix2.pgc"
00148 int c ;
00149
00150 #line 50 "test_informix2.pgc"
00151 timestamp d ;
00152
00153 #line 51 "test_informix2.pgc"
00154 timestamp e ;
00155
00156 #line 52 "test_informix2.pgc"
00157 timestamp maxd ;
00158
00159 #line 53 "test_informix2.pgc"
00160 char dbname [ 30 ] ;
00161
00162 #line 54 "test_informix2.pgc"
00163
00164
00165 interval *intvl;
00166
00167
00168 #line 58 "test_informix2.pgc"
00169
00170
00171 ECPGdebug(1, stderr);
00172
00173 strcpy(dbname, "regress1");
00174 { ECPGconnect(__LINE__, 1, dbname , NULL, NULL , NULL, 0);
00175 #line 63 "test_informix2.pgc"
00176
00177 if (sqlca.sqlcode < 0) sqlprint();}
00178 #line 63 "test_informix2.pgc"
00179
00180 sql_check("main", "connect", 0);
00181
00182 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "set DateStyle to 'DMY'", ECPGt_EOIT, ECPGt_EORT);
00183 #line 66 "test_informix2.pgc"
00184
00185 if (sqlca.sqlcode < 0) sqlprint();}
00186 #line 66 "test_informix2.pgc"
00187
00188
00189 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "create table history ( customerid integer , timestamp timestamp without time zone , action_taken char ( 5 ) , narrative varchar ( 100 ) )", ECPGt_EOIT, ECPGt_EORT);
00190 #line 68 "test_informix2.pgc"
00191
00192 if (sqlca.sqlcode < 0) sqlprint();}
00193 #line 68 "test_informix2.pgc"
00194
00195 sql_check("main", "create", 0);
00196
00197 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into history ( customerid , timestamp , action_taken , narrative ) values ( 1 , '2003-05-07 13:28:34 CEST' , 'test' , 'test' )", ECPGt_EOIT, ECPGt_EORT);
00198 #line 73 "test_informix2.pgc"
00199
00200 if (sqlca.sqlcode < 0) sqlprint();}
00201 #line 73 "test_informix2.pgc"
00202
00203 sql_check("main", "insert", 0);
00204
00205 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select max ( timestamp ) from history", ECPGt_EOIT,
00206 ECPGt_timestamp,&(maxd),(long)1,(long)1,sizeof(timestamp),
00207 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00208 #line 78 "test_informix2.pgc"
00209
00210 if (sqlca.sqlcode < 0) sqlprint();}
00211 #line 78 "test_informix2.pgc"
00212
00213 sql_check("main", "select max", 100);
00214
00215 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select customerid , timestamp from history where timestamp = $1 limit 1",
00216 ECPGt_timestamp,&(maxd),(long)1,(long)1,sizeof(timestamp),
00217 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
00218 ECPGt_int,&(c),(long)1,(long)1,sizeof(int),
00219 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00220 ECPGt_timestamp,&(d),(long)1,(long)1,sizeof(timestamp),
00221 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00222 #line 85 "test_informix2.pgc"
00223
00224 if (sqlca.sqlcode < 0) sqlprint();}
00225 #line 85 "test_informix2.pgc"
00226
00227 sql_check("main", "select", 0);
00228
00229 printf("Read in customer %d\n", c);
00230
00231 intvl = PGTYPESinterval_from_asc("1 day 2 hours 24 minutes 65 seconds", NULL);
00232 PGTYPEStimestamp_add_interval(&d, intvl, &e);
00233 free(intvl);
00234 c++;
00235
00236 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into history ( customerid , timestamp , action_taken , narrative ) values ( $1 , $2 , 'test' , 'test' )",
00237 ECPGt_int,&(c),(long)1,(long)1,sizeof(int),
00238 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00239 ECPGt_timestamp,&(e),(long)1,(long)1,sizeof(timestamp),
00240 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00241 #line 97 "test_informix2.pgc"
00242
00243 if (sqlca.sqlcode < 0) sqlprint();}
00244 #line 97 "test_informix2.pgc"
00245
00246 sql_check("main", "update", 0);
00247
00248 { ECPGtrans(__LINE__, NULL, "commit");
00249 #line 100 "test_informix2.pgc"
00250
00251 if (sqlca.sqlcode < 0) sqlprint();}
00252 #line 100 "test_informix2.pgc"
00253
00254
00255 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table history", ECPGt_EOIT, ECPGt_EORT);
00256 #line 102 "test_informix2.pgc"
00257
00258 if (sqlca.sqlcode < 0) sqlprint();}
00259 #line 102 "test_informix2.pgc"
00260
00261 sql_check("main", "drop", 0);
00262
00263 { ECPGtrans(__LINE__, NULL, "commit");
00264 #line 105 "test_informix2.pgc"
00265
00266 if (sqlca.sqlcode < 0) sqlprint();}
00267 #line 105 "test_informix2.pgc"
00268
00269
00270 { ECPGdisconnect(__LINE__, "CURRENT");
00271 #line 107 "test_informix2.pgc"
00272
00273 if (sqlca.sqlcode < 0) sqlprint();}
00274 #line 107 "test_informix2.pgc"
00275
00276 sql_check("main", "disconnect", 0);
00277
00278 printf("All OK!\n");
00279
00280 exit(0);
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292 }