00001
00002
00003 #include <ecpglib.h>
00004 #include <ecpgerrno.h>
00005 #include <sqlca.h>
00006
00007 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00008
00009 #line 1 "array.pgc"
00010 #include <locale.h>
00011 #include <string.h>
00012 #include <stdlib.h>
00013
00014
00015 #line 5 "array.pgc"
00016
00017
00018
00019 #line 1 "sqlca.h"
00020 #ifndef POSTGRES_SQLCA_H
00021 #define POSTGRES_SQLCA_H
00022
00023 #ifndef PGDLLIMPORT
00024 #if defined(WIN32) || defined(__CYGWIN__)
00025 #define PGDLLIMPORT __declspec (dllimport)
00026 #else
00027 #define PGDLLIMPORT
00028 #endif
00029 #endif
00030
00031 #define SQLERRMC_LEN 150
00032
00033 #ifdef __cplusplus
00034 extern "C"
00035 {
00036 #endif
00037
00038 struct sqlca_t
00039 {
00040 char sqlcaid[8];
00041 long sqlabc;
00042 long sqlcode;
00043 struct
00044 {
00045 int sqlerrml;
00046 char sqlerrmc[SQLERRMC_LEN];
00047 } sqlerrm;
00048 char sqlerrp[8];
00049 long sqlerrd[6];
00050
00051
00052
00053
00054
00055
00056
00057
00058 char sqlwarn[8];
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 char sqlstate[5];
00073 };
00074
00075 struct sqlca_t *ECPGget_sqlca(void);
00076
00077 #ifndef POSTGRES_ECPG_INTERNAL
00078 #define sqlca (*ECPGget_sqlca())
00079 #endif
00080
00081 #ifdef __cplusplus
00082 }
00083 #endif
00084
00085 #endif
00086
00087 #line 7 "array.pgc"
00088
00089
00090 #line 1 "regression.h"
00091
00092
00093
00094
00095
00096
00097 #line 8 "array.pgc"
00098
00099
00100 int
00101 main (void)
00102 {
00103
00104
00105
00106
00107
00108
00109
00110
00111 #line 14 "array.pgc"
00112 int i = 1 ;
00113
00114 #line 15 "array.pgc"
00115 int * did = & i ;
00116
00117 #line 16 "array.pgc"
00118 int a [ 10 ] = { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 } ;
00119
00120 #line 17 "array.pgc"
00121 char text [ 25 ] = "klmnopqrst" ;
00122
00123 #line 18 "array.pgc"
00124 char * t = ( char * ) malloc ( 11 ) ;
00125
00126 #line 19 "array.pgc"
00127 double f ;
00128
00129 #line 20 "array.pgc"
00130
00131
00132 strcpy(t, "0123456789");
00133 setlocale(LC_ALL, "C");
00134
00135 ECPGdebug(1, stderr);
00136
00137 { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0);
00138 #line 27 "array.pgc"
00139
00140 if (sqlca.sqlcode < 0) sqlprint();}
00141 #line 27 "array.pgc"
00142
00143
00144 { ECPGsetcommit(__LINE__, "on", NULL);
00145 #line 29 "array.pgc"
00146
00147 if (sqlca.sqlcode < 0) sqlprint();}
00148 #line 29 "array.pgc"
00149
00150
00151 { ECPGtrans(__LINE__, NULL, "begin work");
00152 #line 31 "array.pgc"
00153
00154 if (sqlca.sqlcode < 0) sqlprint();}
00155 #line 31 "array.pgc"
00156
00157
00158 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( f float , i int , a int [ 10 ] , text char ( 10 ) )", ECPGt_EOIT, ECPGt_EORT);
00159 #line 33 "array.pgc"
00160
00161 if (sqlca.sqlcode < 0) sqlprint();}
00162 #line 33 "array.pgc"
00163
00164
00165 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text ) values ( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' )", ECPGt_EOIT, ECPGt_EORT);
00166 #line 35 "array.pgc"
00167
00168 if (sqlca.sqlcode < 0) sqlprint();}
00169 #line 35 "array.pgc"
00170
00171
00172 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text ) values ( 140787.0 , 2 , $1 , $2 )",
00173 ECPGt_int,(a),(long)1,(long)10,sizeof(int),
00174 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00175 ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char),
00176 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00177 #line 37 "array.pgc"
00178
00179 if (sqlca.sqlcode < 0) sqlprint();}
00180 #line 37 "array.pgc"
00181
00182
00183 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text ) values ( 14.07 , $1 , $2 , $3 )",
00184 ECPGt_int,&(did),(long)1,(long)0,sizeof(int),
00185 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00186 ECPGt_int,(a),(long)1,(long)10,sizeof(int),
00187 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00188 ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char),
00189 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00190 #line 39 "array.pgc"
00191
00192 if (sqlca.sqlcode < 0) sqlprint();}
00193 #line 39 "array.pgc"
00194
00195
00196 { ECPGtrans(__LINE__, NULL, "commit");
00197 #line 41 "array.pgc"
00198
00199 if (sqlca.sqlcode < 0) sqlprint();}
00200 #line 41 "array.pgc"
00201
00202
00203 { ECPGtrans(__LINE__, NULL, "begin work");
00204 #line 43 "array.pgc"
00205
00206 if (sqlca.sqlcode < 0) sqlprint();}
00207 #line 43 "array.pgc"
00208
00209
00210 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select f , text from test where i = 1", ECPGt_EOIT,
00211 ECPGt_double,&(f),(long)1,(long)1,sizeof(double),
00212 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00213 ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char),
00214 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00215 #line 48 "array.pgc"
00216
00217 if (sqlca.sqlcode < 0) sqlprint();}
00218 #line 48 "array.pgc"
00219
00220
00221 printf("Found f=%f text=%10.10s\n", f, text);
00222
00223 f=140787;
00224 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select a , text from test where f = $1 ",
00225 ECPGt_double,&(f),(long)1,(long)1,sizeof(double),
00226 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
00227 ECPGt_int,(a),(long)1,(long)10,sizeof(int),
00228 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00229 ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char),
00230 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00231 #line 56 "array.pgc"
00232
00233 if (sqlca.sqlcode < 0) sqlprint();}
00234 #line 56 "array.pgc"
00235
00236
00237 for (i = 0; i < 10; i++)
00238 printf("Found a[%d] = %d\n", i, a[i]);
00239
00240 printf("Found text=%10.10s\n", t);
00241
00242 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select a from test where f = $1 ",
00243 ECPGt_double,&(f),(long)1,(long)1,sizeof(double),
00244 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
00245 ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char),
00246 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00247 #line 66 "array.pgc"
00248
00249 if (sqlca.sqlcode < 0) sqlprint();}
00250 #line 66 "array.pgc"
00251
00252
00253 printf("Found text=%s\n", text);
00254
00255 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
00256 #line 70 "array.pgc"
00257
00258 if (sqlca.sqlcode < 0) sqlprint();}
00259 #line 70 "array.pgc"
00260
00261
00262 { ECPGtrans(__LINE__, NULL, "commit");
00263 #line 72 "array.pgc"
00264
00265 if (sqlca.sqlcode < 0) sqlprint();}
00266 #line 72 "array.pgc"
00267
00268
00269 { ECPGdisconnect(__LINE__, "CURRENT");
00270 #line 74 "array.pgc"
00271
00272 if (sqlca.sqlcode < 0) sqlprint();}
00273 #line 74 "array.pgc"
00274
00275
00276 free(t);
00277
00278 return (0);
00279 }