1 /* Processed by ecpg (regression mode) */
2 /* These include files are added by the preprocessor */
3 #include <ecpglib.h>
4 #include <ecpgerrno.h>
5 #include <sqlca.h>
6 /* End of automatic include section */
7 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8 
9 #line 1 "array.pgc"
10 #include <locale.h>
11 #include <string.h>
12 #include <stdlib.h>
13 
14 #include <pgtypes_date.h>
15 #include <pgtypes_interval.h>
16 #include <pgtypes_numeric.h>
17 #include <pgtypes_timestamp.h>
18 
19 /* exec sql whenever sqlerror  sqlprint ; */
20 #line 10 "array.pgc"
21 
22 
23 
24 #line 1 "sqlca.h"
25 #ifndef POSTGRES_SQLCA_H
26 #define POSTGRES_SQLCA_H
27 
28 #ifndef PGDLLIMPORT
29 #if  defined(WIN32) || defined(__CYGWIN__)
30 #define PGDLLIMPORT __declspec (dllimport)
31 #else
32 #define PGDLLIMPORT
33 #endif							/* __CYGWIN__ */
34 #endif							/* PGDLLIMPORT */
35 
36 #define SQLERRMC_LEN	150
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42 
43 struct sqlca_t
44 {
45 	char		sqlcaid[8];
46 	long		sqlabc;
47 	long		sqlcode;
48 	struct
49 	{
50 		int			sqlerrml;
51 		char		sqlerrmc[SQLERRMC_LEN];
52 	}			sqlerrm;
53 	char		sqlerrp[8];
54 	long		sqlerrd[6];
55 	/* Element 0: empty						*/
56 	/* 1: OID of processed tuple if applicable			*/
57 	/* 2: number of rows processed				*/
58 	/* after an INSERT, UPDATE or				*/
59 	/* DELETE statement					*/
60 	/* 3: empty						*/
61 	/* 4: empty						*/
62 	/* 5: empty						*/
63 	char		sqlwarn[8];
64 	/* Element 0: set to 'W' if at least one other is 'W'	*/
65 	/* 1: if 'W' at least one character string		*/
66 	/* value was truncated when it was			*/
67 	/* stored into a host variable.             */
68 
69 	/*
70 	 * 2: if 'W' a (hopefully) non-fatal notice occurred
71 	 */	/* 3: empty */
72 	/* 4: empty						*/
73 	/* 5: empty						*/
74 	/* 6: empty						*/
75 	/* 7: empty						*/
76 
77 	char		sqlstate[5];
78 };
79 
80 struct sqlca_t *ECPGget_sqlca(void);
81 
82 #ifndef POSTGRES_ECPG_INTERNAL
83 #define sqlca (*ECPGget_sqlca())
84 #endif
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif
91 
92 #line 12 "array.pgc"
93 
94 
95 #line 1 "regression.h"
96 
97 
98 
99 
100 
101 
102 #line 13 "array.pgc"
103 
104 
105 int
main(void)106 main (void)
107 {
108 /* exec sql begin declare section */
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 #line 19 "array.pgc"
121  int i = 1 , j ;
122 
123 #line 20 "array.pgc"
124  int * did = & i ;
125 
126 #line 21 "array.pgc"
127  short a [ 10 ] = { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 } ;
128 
129 #line 22 "array.pgc"
130  timestamp ts [ 10 ] ;
131 
132 #line 23 "array.pgc"
133  date d [ 10 ] ;
134 
135 #line 24 "array.pgc"
136  interval in [ 10 ] ;
137 
138 #line 25 "array.pgc"
139  numeric n [ 10 ] ;
140 
141 #line 26 "array.pgc"
142  char text [ 25 ] = "klmnopqrst" ;
143 
144 #line 27 "array.pgc"
145  char * t = ( char * ) malloc ( 11 ) ;
146 
147 #line 28 "array.pgc"
148  double f ;
149 /* exec sql end declare section */
150 #line 29 "array.pgc"
151 
152 
153 	strcpy(t, "0123456789");
154 	setlocale(LC_ALL, "C");
155 
156 	ECPGdebug(1, stderr);
157 
158 	for (j = 0; j < 10; j++) {
159 		char str[28];
160 		numeric *value;
161 		interval *inter;
162 
163 		sprintf(str, "2000-1-1 0%d:00:00", j);
164 		ts[j] = PGTYPEStimestamp_from_asc(str, NULL);
165 		sprintf(str, "2000-1-1%d\n", j);
166 		d[j] = PGTYPESdate_from_asc(str, NULL);
167 		sprintf(str, "%d hours", j+10);
168 		inter = PGTYPESinterval_from_asc(str, NULL);
169 		in[j] = *inter;
170 		value = PGTYPESnumeric_new();
171 		PGTYPESnumeric_from_int(j, value);
172 		n[j] = *value;
173 	}
174 
175         { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
176 #line 53 "array.pgc"
177 
178 if (sqlca.sqlcode < 0) sqlprint();}
179 #line 53 "array.pgc"
180 
181 
182 	{ ECPGsetcommit(__LINE__, "on", NULL);
183 #line 55 "array.pgc"
184 
185 if (sqlca.sqlcode < 0) sqlprint();}
186 #line 55 "array.pgc"
187 
188 
189 	{ ECPGtrans(__LINE__, NULL, "begin work");
190 #line 57 "array.pgc"
191 
192 if (sqlca.sqlcode < 0) sqlprint();}
193 #line 57 "array.pgc"
194 
195 
196 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( f float , i int , a int [ 10 ] , text char ( 10 ) , ts timestamp [ 10 ] , n numeric [ 10 ] , d date [ 10 ] , inter interval [ 10 ] )", ECPGt_EOIT, ECPGt_EORT);
197 #line 59 "array.pgc"
198 
199 if (sqlca.sqlcode < 0) sqlprint();}
200 #line 59 "array.pgc"
201 
202 
203 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text , ts , n , d , inter ) values ( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' , $1  , $2  , $3  , $4  )",
204 	ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp),
205 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
206 	ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric),
207 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
208 	ECPGt_date,&(d),(long)1,(long)10,sizeof(date),
209 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
210 	ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval),
211 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
212 #line 61 "array.pgc"
213 
214 if (sqlca.sqlcode < 0) sqlprint();}
215 #line 61 "array.pgc"
216 
217 
218 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text , ts , n , d , inter ) values ( 140787.0 , 2 , $1  , $2  , $3  , $4  , $5  , $6  )",
219 	ECPGt_short,(a),(long)1,(long)10,sizeof(short),
220 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
221 	ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char),
222 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
223 	ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp),
224 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
225 	ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric),
226 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
227 	ECPGt_date,&(d),(long)1,(long)10,sizeof(date),
228 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
229 	ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval),
230 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
231 #line 63 "array.pgc"
232 
233 if (sqlca.sqlcode < 0) sqlprint();}
234 #line 63 "array.pgc"
235 
236 
237 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text , ts , n , d , inter ) values ( 14.07 , $1  , $2  , $3  , $4  , $5  , $6  , $7  )",
238 	ECPGt_int,&(did),(long)1,(long)0,sizeof(int),
239 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
240 	ECPGt_short,(a),(long)1,(long)10,sizeof(short),
241 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
242 	ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char),
243 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
244 	ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp),
245 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
246 	ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric),
247 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
248 	ECPGt_date,&(d),(long)1,(long)10,sizeof(date),
249 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
250 	ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval),
251 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
252 #line 65 "array.pgc"
253 
254 if (sqlca.sqlcode < 0) sqlprint();}
255 #line 65 "array.pgc"
256 
257 
258 	{ ECPGtrans(__LINE__, NULL, "commit");
259 #line 67 "array.pgc"
260 
261 if (sqlca.sqlcode < 0) sqlprint();}
262 #line 67 "array.pgc"
263 
264 
265 	for (j = 0; j < 10; j++) {
266 		ts[j] = PGTYPEStimestamp_from_asc("1900-01-01 00:00:00", NULL);
267 		d[j] = PGTYPESdate_from_asc("1900-01-01", NULL);
268 		in[j] = *PGTYPESinterval_new();
269 		n[j] = *PGTYPESnumeric_new();
270 	}
271 	{ ECPGtrans(__LINE__, NULL, "begin work");
272 #line 75 "array.pgc"
273 
274 if (sqlca.sqlcode < 0) sqlprint();}
275 #line 75 "array.pgc"
276 
277 
278 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select f , text from test where i = 1", ECPGt_EOIT,
279 	ECPGt_double,&(f),(long)1,(long)1,sizeof(double),
280 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
281 	ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char),
282 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
283 #line 80 "array.pgc"
284 
285 if (sqlca.sqlcode < 0) sqlprint();}
286 #line 80 "array.pgc"
287 
288 
289 	printf("Found f=%f text=%10.10s\n", f, text);
290 
291 	f=140787;
292 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select a , text , ts , n , d , inter from test where f = $1 ",
293 	ECPGt_double,&(f),(long)1,(long)1,sizeof(double),
294 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
295 	ECPGt_short,(a),(long)1,(long)10,sizeof(short),
296 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
297 	ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char),
298 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
299 	ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp),
300 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
301 	ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric),
302 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
303 	ECPGt_date,&(d),(long)1,(long)10,sizeof(date),
304 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
305 	ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval),
306 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
307 #line 88 "array.pgc"
308 
309 if (sqlca.sqlcode < 0) sqlprint();}
310 #line 88 "array.pgc"
311 
312 
313 	for (i = 0; i < 10; i++)
314 		printf("Found a[%d] = %d ts[%d] = %s n[%d] = %s d[%d] = %s in[%d] = %s\n", i, a[i], i, PGTYPEStimestamp_to_asc(ts[i]), i, PGTYPESnumeric_to_asc(&(n[i]), -1), i, PGTYPESdate_to_asc(d[i]), i, PGTYPESinterval_to_asc(&(in[i])));
315 
316 	printf("Found text=%10.10s\n", t);
317 
318 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select a from test where f = $1 ",
319 	ECPGt_double,&(f),(long)1,(long)1,sizeof(double),
320 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
321 	ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char),
322 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
323 #line 98 "array.pgc"
324 
325 if (sqlca.sqlcode < 0) sqlprint();}
326 #line 98 "array.pgc"
327 
328 
329 	printf("Found text=%s\n", text);
330 
331 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
332 #line 102 "array.pgc"
333 
334 if (sqlca.sqlcode < 0) sqlprint();}
335 #line 102 "array.pgc"
336 
337 
338 	{ ECPGtrans(__LINE__, NULL, "commit");
339 #line 104 "array.pgc"
340 
341 if (sqlca.sqlcode < 0) sqlprint();}
342 #line 104 "array.pgc"
343 
344 
345 	{ ECPGdisconnect(__LINE__, "CURRENT");
346 #line 106 "array.pgc"
347 
348 if (sqlca.sqlcode < 0) sqlprint();}
349 #line 106 "array.pgc"
350 
351 
352 	free(t);
353 
354 	return 0;
355 }
356