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 "sqlda.pgc"
10 #include <stdlib.h>
11 #include <string.h>
12 #include <limits.h>
13 #include "ecpg_config.h"
14 
15 
16 #line 1 "regression.h"
17 
18 
19 
20 
21 
22 
23 #line 6 "sqlda.pgc"
24 
25 
26 #line 1 "sqlda.h"
27 #ifndef ECPG_SQLDA_H
28 #define ECPG_SQLDA_H
29 
30 #ifdef _ECPG_INFORMIX_H
31 
32 #include "sqlda-compat.h"
33 typedef struct sqlvar_compat sqlvar_t;
34 typedef struct sqlda_compat sqlda_t;
35 
36 #else
37 
38 #include "sqlda-native.h"
39 typedef struct sqlvar_struct sqlvar_t;
40 typedef struct sqlda_struct sqlda_t;
41 
42 #endif
43 
44 #endif							/* ECPG_SQLDA_H */
45 
46 #line 7 "sqlda.pgc"
47 
48 
49 #line 1 "pgtypes_numeric.h"
50 #ifndef PGTYPES_NUMERIC
51 #define PGTYPES_NUMERIC
52 
53 #include <pgtypes.h>
54 
55 #define NUMERIC_POS						0x0000
56 #define NUMERIC_NEG						0x4000
57 #define NUMERIC_NAN						0xC000
58 #define NUMERIC_NULL						0xF000
59 #define NUMERIC_MAX_PRECISION			1000
60 #define NUMERIC_MAX_DISPLAY_SCALE		NUMERIC_MAX_PRECISION
61 #define NUMERIC_MIN_DISPLAY_SCALE		0
62 #define NUMERIC_MIN_SIG_DIGITS			16
63 
64 #define DECSIZE 30
65 
66 typedef unsigned char NumericDigit;
67 typedef struct
68 {
69 	int			ndigits;		/* number of digits in digits[] - can be 0! */
70 	int			weight;			/* weight of first digit */
71 	int			rscale;			/* result scale */
72 	int			dscale;			/* display scale */
73 	int			sign;			/* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
74 	NumericDigit *buf;			/* start of alloc'd space for digits[] */
75 	NumericDigit *digits;		/* decimal digits */
76 } numeric;
77 
78 typedef struct
79 {
80 	int			ndigits;		/* number of digits in digits[] - can be 0! */
81 	int			weight;			/* weight of first digit */
82 	int			rscale;			/* result scale */
83 	int			dscale;			/* display scale */
84 	int			sign;			/* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
85 	NumericDigit digits[DECSIZE];	/* decimal digits */
86 } decimal;
87 
88 #ifdef __cplusplus
89 extern "C"
90 {
91 #endif
92 
93 numeric    *PGTYPESnumeric_new(void);
94 decimal    *PGTYPESdecimal_new(void);
95 void		PGTYPESnumeric_free(numeric *);
96 void		PGTYPESdecimal_free(decimal *);
97 numeric    *PGTYPESnumeric_from_asc(char *, char **);
98 char	   *PGTYPESnumeric_to_asc(numeric *, int);
99 int			PGTYPESnumeric_add(numeric *, numeric *, numeric *);
100 int			PGTYPESnumeric_sub(numeric *, numeric *, numeric *);
101 int			PGTYPESnumeric_mul(numeric *, numeric *, numeric *);
102 int			PGTYPESnumeric_div(numeric *, numeric *, numeric *);
103 int			PGTYPESnumeric_cmp(numeric *, numeric *);
104 int			PGTYPESnumeric_from_int(signed int, numeric *);
105 int			PGTYPESnumeric_from_long(signed long int, numeric *);
106 int			PGTYPESnumeric_copy(numeric *, numeric *);
107 int			PGTYPESnumeric_from_double(double, numeric *);
108 int			PGTYPESnumeric_to_double(numeric *, double *);
109 int			PGTYPESnumeric_to_int(numeric *, int *);
110 int			PGTYPESnumeric_to_long(numeric *, long *);
111 int			PGTYPESnumeric_to_decimal(numeric *, decimal *);
112 int			PGTYPESnumeric_from_decimal(decimal *, numeric *);
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #endif							/* PGTYPES_NUMERIC */
119 
120 #line 8 "sqlda.pgc"
121 
122 
123 /* exec sql whenever sqlerror  stop ; */
124 #line 10 "sqlda.pgc"
125 
126 
127 /* These shouldn't be under DECLARE SECTION */
128 sqlda_t	*inp_sqlda, *outp_sqlda, *outp_sqlda1;
129 
130 static void
dump_sqlda(sqlda_t * sqlda)131 dump_sqlda(sqlda_t *sqlda)
132 {
133 	int	i;
134 
135 	if (sqlda == NULL)
136 	{
137 		printf("dump_sqlda called with NULL sqlda\n");
138 		return;
139 	}
140 
141 	for (i = 0; i < sqlda->sqld; i++)
142 	{
143 		if (sqlda->sqlvar[i].sqlind && *(sqlda->sqlvar[i].sqlind) == -1)
144 			printf("name sqlda descriptor: '%s' value NULL'\n", sqlda->sqlvar[i].sqlname.data);
145 		else
146 		switch (sqlda->sqlvar[i].sqltype)
147 		{
148 		case ECPGt_char:
149 			printf("name sqlda descriptor: '%s' value '%s'\n", sqlda->sqlvar[i].sqlname.data, sqlda->sqlvar[i].sqldata);
150 			break;
151 		case ECPGt_int:
152 			printf("name sqlda descriptor: '%s' value %d\n", sqlda->sqlvar[i].sqlname.data, *(int *)sqlda->sqlvar[i].sqldata);
153 			break;
154 		case ECPGt_long:
155 			printf("name sqlda descriptor: '%s' value %ld\n", sqlda->sqlvar[i].sqlname.data, *(long int *)sqlda->sqlvar[i].sqldata);
156 			break;
157 		case ECPGt_long_long:
158 			printf(
159 #ifdef _WIN32
160 				"name sqlda descriptor: '%s' value %I64d\n",
161 #else
162 				"name sqlda descriptor: '%s' value %lld\n",
163 #endif
164 				sqlda->sqlvar[i].sqlname.data, *(long long int *)sqlda->sqlvar[i].sqldata);
165 			break;
166 		case ECPGt_double:
167 			printf("name sqlda descriptor: '%s' value %f\n", sqlda->sqlvar[i].sqlname.data, *(double *)sqlda->sqlvar[i].sqldata);
168 			break;
169 		case ECPGt_numeric:
170 			{
171 				char    *val;
172 
173 				val = PGTYPESnumeric_to_asc((numeric*)sqlda->sqlvar[i].sqldata, -1);
174 				printf("name sqlda descriptor: '%s' value NUMERIC '%s'\n", sqlda->sqlvar[i].sqlname.data, val);
175 				PGTYPESchar_free(val);
176 				break;
177 			}
178 		}
179 	}
180 }
181 
182 int
main(void)183 main (void)
184 {
185 /* exec sql begin declare section */
186 
187 
188 
189 
190 
191 #line 71 "sqlda.pgc"
192  char * stmt1 = "SELECT * FROM t1" ;
193 
194 #line 72 "sqlda.pgc"
195  char * stmt2 = "SELECT * FROM t1 WHERE id = ?" ;
196 
197 #line 73 "sqlda.pgc"
198  int rec ;
199 
200 #line 74 "sqlda.pgc"
201  int id ;
202 /* exec sql end declare section */
203 #line 75 "sqlda.pgc"
204 
205 
206 	char msg[128];
207 
208 	ECPGdebug(1, stderr);
209 
210 	strcpy(msg, "connect");
211 	{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "regress1", 0);
212 #line 82 "sqlda.pgc"
213 
214 if (sqlca.sqlcode < 0) exit (1);}
215 #line 82 "sqlda.pgc"
216 
217 
218 	strcpy(msg, "set");
219 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
220 #line 85 "sqlda.pgc"
221 
222 if (sqlca.sqlcode < 0) exit (1);}
223 #line 85 "sqlda.pgc"
224 
225 
226 	strcpy(msg, "create");
227 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table t1 ( id integer , t text , d1 numeric , d2 float8 , c char ( 10 ) , big bigint )", ECPGt_EOIT, ECPGt_EORT);
228 #line 95 "sqlda.pgc"
229 
230 if (sqlca.sqlcode < 0) exit (1);}
231 #line 95 "sqlda.pgc"
232 
233 
234 	strcpy(msg, "insert");
235 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t1 values ( 1 , 'a' , 1.0 , 1 , 'a' , 1111111111111111111 ) , ( 2 , null , null , null , null , null ) , ( 3 , 'c' , 0.0 , 3 , 'c' , 3333333333333333333 ) , ( 4 , 'd' , 'NaN' , 4 , 'd' , 4444444444444444444 ) , ( 5 , 'e' , 0.001234 , 5 , 'e' , 5555555555555555555 )", ECPGt_EOIT, ECPGt_EORT);
236 #line 103 "sqlda.pgc"
237 
238 if (sqlca.sqlcode < 0) exit (1);}
239 #line 103 "sqlda.pgc"
240 
241 
242 	strcpy(msg, "commit");
243 	{ ECPGtrans(__LINE__, NULL, "commit");
244 #line 106 "sqlda.pgc"
245 
246 if (sqlca.sqlcode < 0) exit (1);}
247 #line 106 "sqlda.pgc"
248 
249 
250 	/* SQLDA test for getting all records from a table */
251 
252 	outp_sqlda = NULL;
253 
254 	strcpy(msg, "prepare");
255 	{ ECPGprepare(__LINE__, NULL, 0, "st_id1", stmt1);
256 #line 113 "sqlda.pgc"
257 
258 if (sqlca.sqlcode < 0) exit (1);}
259 #line 113 "sqlda.pgc"
260 
261 
262 	strcpy(msg, "declare");
263 	/* declare mycur1 cursor for $1 */
264 #line 116 "sqlda.pgc"
265 
266 
267 	strcpy(msg, "open");
268 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur1 cursor for $1",
269 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id1", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
270 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
271 #line 119 "sqlda.pgc"
272 
273 if (sqlca.sqlcode < 0) exit (1);}
274 #line 119 "sqlda.pgc"
275 
276 
277 	/* exec sql whenever not found  break ; */
278 #line 121 "sqlda.pgc"
279 
280 
281 	rec = 0;
282 	while (1)
283 	{
284 		strcpy(msg, "fetch");
285 		{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT,
286 	ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
287 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
288 #line 127 "sqlda.pgc"
289 
290 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
291 #line 127 "sqlda.pgc"
292 
293 if (sqlca.sqlcode < 0) exit (1);}
294 #line 127 "sqlda.pgc"
295 
296 
297 		printf("FETCH RECORD %d\n", ++rec);
298 		dump_sqlda(outp_sqlda);
299 	}
300 
301 	/* exec sql whenever not found  continue ; */
302 #line 133 "sqlda.pgc"
303 
304 
305 	strcpy(msg, "close");
306 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur1", ECPGt_EOIT, ECPGt_EORT);
307 #line 136 "sqlda.pgc"
308 
309 if (sqlca.sqlcode < 0) exit (1);}
310 #line 136 "sqlda.pgc"
311 
312 
313 	strcpy(msg, "deallocate");
314 	{ ECPGdeallocate(__LINE__, 0, NULL, "st_id1");
315 #line 139 "sqlda.pgc"
316 
317 if (sqlca.sqlcode < 0) exit (1);}
318 #line 139 "sqlda.pgc"
319 
320 
321 	free(outp_sqlda);
322 
323 	/* SQLDA test for getting ALL records into the sqlda list */
324 
325 	outp_sqlda = NULL;
326 
327 	strcpy(msg, "prepare");
328 	{ ECPGprepare(__LINE__, NULL, 0, "st_id2", stmt1);
329 #line 148 "sqlda.pgc"
330 
331 if (sqlca.sqlcode < 0) exit (1);}
332 #line 148 "sqlda.pgc"
333 
334 
335 	strcpy(msg, "declare");
336 	/* declare mycur2 cursor for $1 */
337 #line 151 "sqlda.pgc"
338 
339 
340 	strcpy(msg, "open");
341 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur2 cursor for $1",
342 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
343 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
344 #line 154 "sqlda.pgc"
345 
346 if (sqlca.sqlcode < 0) exit (1);}
347 #line 154 "sqlda.pgc"
348 
349 
350 	strcpy(msg, "fetch");
351 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch all from mycur2", ECPGt_EOIT,
352 	ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
353 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
354 #line 157 "sqlda.pgc"
355 
356 if (sqlca.sqlcode < 0) exit (1);}
357 #line 157 "sqlda.pgc"
358 
359 
360 	outp_sqlda1 = outp_sqlda;
361 	rec = 0;
362 	while (outp_sqlda1)
363 	{
364 		sqlda_t	*ptr;
365 		printf("FETCH RECORD %d\n", ++rec);
366 		dump_sqlda(outp_sqlda1);
367 
368 		ptr = outp_sqlda1;
369 		outp_sqlda1 = outp_sqlda1->desc_next;
370 		free(ptr);
371 	}
372 
373 	strcpy(msg, "close");
374 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur2", ECPGt_EOIT, ECPGt_EORT);
375 #line 173 "sqlda.pgc"
376 
377 if (sqlca.sqlcode < 0) exit (1);}
378 #line 173 "sqlda.pgc"
379 
380 
381 	strcpy(msg, "deallocate");
382 	{ ECPGdeallocate(__LINE__, 0, NULL, "st_id2");
383 #line 176 "sqlda.pgc"
384 
385 if (sqlca.sqlcode < 0) exit (1);}
386 #line 176 "sqlda.pgc"
387 
388 
389 	/* SQLDA test for getting one record using an input descriptor */
390 
391 	/*
392 	 * Input sqlda has to be built manually
393 	 * sqlda_t contains 1 sqlvar_t structure already.
394 	 */
395 	inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
396 	memset(inp_sqlda, 0, sizeof(sqlda_t));
397 	inp_sqlda->sqln = 1;
398 
399 	inp_sqlda->sqlvar[0].sqltype = ECPGt_int;
400 	inp_sqlda->sqlvar[0].sqldata = (char *)&id;
401 
402 	printf("EXECUTE RECORD 4\n");
403 
404 	id = 4;
405 
406 	outp_sqlda = NULL;
407 
408 	strcpy(msg, "prepare");
409 	{ ECPGprepare(__LINE__, NULL, 0, "st_id3", stmt2);
410 #line 198 "sqlda.pgc"
411 
412 if (sqlca.sqlcode < 0) exit (1);}
413 #line 198 "sqlda.pgc"
414 
415 
416 	strcpy(msg, "execute");
417 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "st_id3",
418 	ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L,
419 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
420 	ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
421 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
422 #line 201 "sqlda.pgc"
423 
424 if (sqlca.sqlcode < 0) exit (1);}
425 #line 201 "sqlda.pgc"
426 
427 
428 	dump_sqlda(outp_sqlda);
429 
430 	strcpy(msg, "deallocate");
431 	{ ECPGdeallocate(__LINE__, 0, NULL, "st_id3");
432 #line 206 "sqlda.pgc"
433 
434 if (sqlca.sqlcode < 0) exit (1);}
435 #line 206 "sqlda.pgc"
436 
437 
438 	free(inp_sqlda);
439 	free(outp_sqlda);
440 
441 	/* SQLDA test for getting one record using an input descriptor
442 	 * on a named connection
443 	 */
444 
445 	{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "con2", 0);
446 #line 215 "sqlda.pgc"
447 
448 if (sqlca.sqlcode < 0) exit (1);}
449 #line 215 "sqlda.pgc"
450 
451 
452 	/*
453 	 * Input sqlda has to be built manually
454 	 * sqlda_t contains 1 sqlvar_t structure already.
455 	 */
456 	inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
457 	memset(inp_sqlda, 0, sizeof(sqlda_t));
458 	inp_sqlda->sqln = 1;
459 
460 	inp_sqlda->sqlvar[0].sqltype = ECPGt_int;
461 	inp_sqlda->sqlvar[0].sqldata = (char *)&id;
462 
463 	printf("EXECUTE RECORD 4\n");
464 
465 	id = 4;
466 
467 	outp_sqlda = NULL;
468 
469 	strcpy(msg, "prepare");
470 	{ ECPGprepare(__LINE__, "con2", 0, "st_id4", stmt2);
471 #line 235 "sqlda.pgc"
472 
473 if (sqlca.sqlcode < 0) exit (1);}
474 #line 235 "sqlda.pgc"
475 
476 
477 	strcpy(msg, "execute");
478 	{ ECPGdo(__LINE__, 0, 1, "con2", 0, ECPGst_execute, "st_id4",
479 	ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L,
480 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
481 	ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
482 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
483 #line 238 "sqlda.pgc"
484 
485 if (sqlca.sqlcode < 0) exit (1);}
486 #line 238 "sqlda.pgc"
487 
488 
489 	dump_sqlda(outp_sqlda);
490 
491 	strcpy(msg, "commit");
492 	{ ECPGtrans(__LINE__, "con2", "commit");
493 #line 243 "sqlda.pgc"
494 
495 if (sqlca.sqlcode < 0) exit (1);}
496 #line 243 "sqlda.pgc"
497 
498 
499 	strcpy(msg, "deallocate");
500 	{ ECPGdeallocate(__LINE__, 0, NULL, "st_id4");
501 #line 246 "sqlda.pgc"
502 
503 if (sqlca.sqlcode < 0) exit (1);}
504 #line 246 "sqlda.pgc"
505 
506 
507 	free(inp_sqlda);
508 	free(outp_sqlda);
509 
510 	strcpy(msg, "disconnect");
511 	{ ECPGdisconnect(__LINE__, "con2");
512 #line 252 "sqlda.pgc"
513 
514 if (sqlca.sqlcode < 0) exit (1);}
515 #line 252 "sqlda.pgc"
516 
517 
518 	/* End test */
519 
520 	strcpy(msg, "drop");
521 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
522 #line 257 "sqlda.pgc"
523 
524 if (sqlca.sqlcode < 0) exit (1);}
525 #line 257 "sqlda.pgc"
526 
527 
528 	strcpy(msg, "commit");
529 	{ ECPGtrans(__LINE__, NULL, "commit");
530 #line 260 "sqlda.pgc"
531 
532 if (sqlca.sqlcode < 0) exit (1);}
533 #line 260 "sqlda.pgc"
534 
535 
536 	strcpy(msg, "disconnect");
537 	{ ECPGdisconnect(__LINE__, "CURRENT");
538 #line 263 "sqlda.pgc"
539 
540 if (sqlca.sqlcode < 0) exit (1);}
541 #line 263 "sqlda.pgc"
542 
543 
544 	return 0;
545 }
546