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 #ifdef HAVE_LONG_LONG_INT
158 		case ECPGt_long_long:
159 			printf("name sqlda descriptor: '%s' value %lld\n", sqlda->sqlvar[i].sqlname.data, *(long long int *)sqlda->sqlvar[i].sqldata);
160 			break;
161 #endif
162 		case ECPGt_double:
163 			printf("name sqlda descriptor: '%s' value %f\n", sqlda->sqlvar[i].sqlname.data, *(double *)sqlda->sqlvar[i].sqldata);
164 			break;
165 		case ECPGt_numeric:
166 			{
167 				char    *val;
168 
169 				val = PGTYPESnumeric_to_asc((numeric*)sqlda->sqlvar[i].sqldata, -1);
170 				printf("name sqlda descriptor: '%s' value NUMERIC '%s'\n", sqlda->sqlvar[i].sqlname.data, val);
171 				PGTYPESchar_free(val);
172 				break;
173 			}
174 		}
175 	}
176 }
177 
178 int
main(void)179 main (void)
180 {
181 /* exec sql begin declare section */
182 
183 
184 
185 
186 
187 #line 67 "sqlda.pgc"
188  char * stmt1 = "SELECT * FROM t1" ;
189 
190 #line 68 "sqlda.pgc"
191  char * stmt2 = "SELECT * FROM t1 WHERE id = ?" ;
192 
193 #line 69 "sqlda.pgc"
194  int rec ;
195 
196 #line 70 "sqlda.pgc"
197  int id ;
198 /* exec sql end declare section */
199 #line 71 "sqlda.pgc"
200 
201 
202 	char msg[128];
203 
204 	ECPGdebug(1, stderr);
205 
206 	strcpy(msg, "connect");
207 	{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "regress1", 0);
208 #line 78 "sqlda.pgc"
209 
210 if (sqlca.sqlcode < 0) exit (1);}
211 #line 78 "sqlda.pgc"
212 
213 
214 	strcpy(msg, "set");
215 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
216 #line 81 "sqlda.pgc"
217 
218 if (sqlca.sqlcode < 0) exit (1);}
219 #line 81 "sqlda.pgc"
220 
221 
222 	strcpy(msg, "create");
223 	{ 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);
224 #line 91 "sqlda.pgc"
225 
226 if (sqlca.sqlcode < 0) exit (1);}
227 #line 91 "sqlda.pgc"
228 
229 
230 	strcpy(msg, "insert");
231 	{ 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);
232 #line 99 "sqlda.pgc"
233 
234 if (sqlca.sqlcode < 0) exit (1);}
235 #line 99 "sqlda.pgc"
236 
237 
238 	strcpy(msg, "commit");
239 	{ ECPGtrans(__LINE__, NULL, "commit");
240 #line 102 "sqlda.pgc"
241 
242 if (sqlca.sqlcode < 0) exit (1);}
243 #line 102 "sqlda.pgc"
244 
245 
246 	/* SQLDA test for getting all records from a table */
247 
248 	outp_sqlda = NULL;
249 
250 	strcpy(msg, "prepare");
251 	{ ECPGprepare(__LINE__, NULL, 0, "st_id1", stmt1);
252 #line 109 "sqlda.pgc"
253 
254 if (sqlca.sqlcode < 0) exit (1);}
255 #line 109 "sqlda.pgc"
256 
257 
258 	strcpy(msg, "declare");
259 	/* declare mycur1 cursor for $1 */
260 #line 112 "sqlda.pgc"
261 
262 
263 	strcpy(msg, "open");
264 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur1 cursor for $1",
265 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id1", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
266 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
267 #line 115 "sqlda.pgc"
268 
269 if (sqlca.sqlcode < 0) exit (1);}
270 #line 115 "sqlda.pgc"
271 
272 
273 	/* exec sql whenever not found  break ; */
274 #line 117 "sqlda.pgc"
275 
276 
277 	rec = 0;
278 	while (1)
279 	{
280 		strcpy(msg, "fetch");
281 		{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT,
282 	ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
283 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
284 #line 123 "sqlda.pgc"
285 
286 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
287 #line 123 "sqlda.pgc"
288 
289 if (sqlca.sqlcode < 0) exit (1);}
290 #line 123 "sqlda.pgc"
291 
292 
293 		printf("FETCH RECORD %d\n", ++rec);
294 		dump_sqlda(outp_sqlda);
295 	}
296 
297 	/* exec sql whenever not found  continue ; */
298 #line 129 "sqlda.pgc"
299 
300 
301 	strcpy(msg, "close");
302 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur1", ECPGt_EOIT, ECPGt_EORT);
303 #line 132 "sqlda.pgc"
304 
305 if (sqlca.sqlcode < 0) exit (1);}
306 #line 132 "sqlda.pgc"
307 
308 
309 	strcpy(msg, "deallocate");
310 	{ ECPGdeallocate(__LINE__, 0, NULL, "st_id1");
311 #line 135 "sqlda.pgc"
312 
313 if (sqlca.sqlcode < 0) exit (1);}
314 #line 135 "sqlda.pgc"
315 
316 
317 	free(outp_sqlda);
318 
319 	/* SQLDA test for getting ALL records into the sqlda list */
320 
321 	outp_sqlda = NULL;
322 
323 	strcpy(msg, "prepare");
324 	{ ECPGprepare(__LINE__, NULL, 0, "st_id2", stmt1);
325 #line 144 "sqlda.pgc"
326 
327 if (sqlca.sqlcode < 0) exit (1);}
328 #line 144 "sqlda.pgc"
329 
330 
331 	strcpy(msg, "declare");
332 	/* declare mycur2 cursor for $1 */
333 #line 147 "sqlda.pgc"
334 
335 
336 	strcpy(msg, "open");
337 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur2 cursor for $1",
338 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
339 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
340 #line 150 "sqlda.pgc"
341 
342 if (sqlca.sqlcode < 0) exit (1);}
343 #line 150 "sqlda.pgc"
344 
345 
346 	strcpy(msg, "fetch");
347 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch all from mycur2", ECPGt_EOIT,
348 	ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
349 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
350 #line 153 "sqlda.pgc"
351 
352 if (sqlca.sqlcode < 0) exit (1);}
353 #line 153 "sqlda.pgc"
354 
355 
356 	outp_sqlda1 = outp_sqlda;
357 	rec = 0;
358 	while (outp_sqlda1)
359 	{
360 		sqlda_t	*ptr;
361 		printf("FETCH RECORD %d\n", ++rec);
362 		dump_sqlda(outp_sqlda1);
363 
364 		ptr = outp_sqlda1;
365 		outp_sqlda1 = outp_sqlda1->desc_next;
366 		free(ptr);
367 	}
368 
369 	strcpy(msg, "close");
370 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur2", ECPGt_EOIT, ECPGt_EORT);
371 #line 169 "sqlda.pgc"
372 
373 if (sqlca.sqlcode < 0) exit (1);}
374 #line 169 "sqlda.pgc"
375 
376 
377 	strcpy(msg, "deallocate");
378 	{ ECPGdeallocate(__LINE__, 0, NULL, "st_id2");
379 #line 172 "sqlda.pgc"
380 
381 if (sqlca.sqlcode < 0) exit (1);}
382 #line 172 "sqlda.pgc"
383 
384 
385 	/* SQLDA test for getting one record using an input descriptor */
386 
387 	/*
388 	 * Input sqlda has to be built manually
389 	 * sqlda_t contains 1 sqlvar_t structure already.
390 	 */
391 	inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
392 	memset(inp_sqlda, 0, sizeof(sqlda_t));
393 	inp_sqlda->sqln = 1;
394 
395 	inp_sqlda->sqlvar[0].sqltype = ECPGt_int;
396 	inp_sqlda->sqlvar[0].sqldata = (char *)&id;
397 
398 	printf("EXECUTE RECORD 4\n");
399 
400 	id = 4;
401 
402 	outp_sqlda = NULL;
403 
404 	strcpy(msg, "prepare");
405 	{ ECPGprepare(__LINE__, NULL, 0, "st_id3", stmt2);
406 #line 194 "sqlda.pgc"
407 
408 if (sqlca.sqlcode < 0) exit (1);}
409 #line 194 "sqlda.pgc"
410 
411 
412 	strcpy(msg, "execute");
413 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "st_id3",
414 	ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L,
415 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
416 	ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
417 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
418 #line 197 "sqlda.pgc"
419 
420 if (sqlca.sqlcode < 0) exit (1);}
421 #line 197 "sqlda.pgc"
422 
423 
424 	dump_sqlda(outp_sqlda);
425 
426 	strcpy(msg, "deallocate");
427 	{ ECPGdeallocate(__LINE__, 0, NULL, "st_id3");
428 #line 202 "sqlda.pgc"
429 
430 if (sqlca.sqlcode < 0) exit (1);}
431 #line 202 "sqlda.pgc"
432 
433 
434 	free(inp_sqlda);
435 	free(outp_sqlda);
436 
437 	/* SQLDA test for getting one record using an input descriptor
438 	 * on a named connection
439 	 */
440 
441 	{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "con2", 0);
442 #line 211 "sqlda.pgc"
443 
444 if (sqlca.sqlcode < 0) exit (1);}
445 #line 211 "sqlda.pgc"
446 
447 
448 	/*
449 	 * Input sqlda has to be built manually
450 	 * sqlda_t contains 1 sqlvar_t structure already.
451 	 */
452 	inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
453 	memset(inp_sqlda, 0, sizeof(sqlda_t));
454 	inp_sqlda->sqln = 1;
455 
456 	inp_sqlda->sqlvar[0].sqltype = ECPGt_int;
457 	inp_sqlda->sqlvar[0].sqldata = (char *)&id;
458 
459 	printf("EXECUTE RECORD 4\n");
460 
461 	id = 4;
462 
463 	outp_sqlda = NULL;
464 
465 	strcpy(msg, "prepare");
466 	{ ECPGprepare(__LINE__, "con2", 0, "st_id4", stmt2);
467 #line 231 "sqlda.pgc"
468 
469 if (sqlca.sqlcode < 0) exit (1);}
470 #line 231 "sqlda.pgc"
471 
472 
473 	strcpy(msg, "execute");
474 	{ ECPGdo(__LINE__, 0, 1, "con2", 0, ECPGst_execute, "st_id4",
475 	ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L,
476 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
477 	ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
478 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
479 #line 234 "sqlda.pgc"
480 
481 if (sqlca.sqlcode < 0) exit (1);}
482 #line 234 "sqlda.pgc"
483 
484 
485 	dump_sqlda(outp_sqlda);
486 
487 	strcpy(msg, "commit");
488 	{ ECPGtrans(__LINE__, "con2", "commit");
489 #line 239 "sqlda.pgc"
490 
491 if (sqlca.sqlcode < 0) exit (1);}
492 #line 239 "sqlda.pgc"
493 
494 
495 	strcpy(msg, "deallocate");
496 	{ ECPGdeallocate(__LINE__, 0, NULL, "st_id4");
497 #line 242 "sqlda.pgc"
498 
499 if (sqlca.sqlcode < 0) exit (1);}
500 #line 242 "sqlda.pgc"
501 
502 
503 	free(inp_sqlda);
504 	free(outp_sqlda);
505 
506 	strcpy(msg, "disconnect");
507 	{ ECPGdisconnect(__LINE__, "con2");
508 #line 248 "sqlda.pgc"
509 
510 if (sqlca.sqlcode < 0) exit (1);}
511 #line 248 "sqlda.pgc"
512 
513 
514 	/* End test */
515 
516 	strcpy(msg, "drop");
517 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
518 #line 253 "sqlda.pgc"
519 
520 if (sqlca.sqlcode < 0) exit (1);}
521 #line 253 "sqlda.pgc"
522 
523 
524 	strcpy(msg, "commit");
525 	{ ECPGtrans(__LINE__, NULL, "commit");
526 #line 256 "sqlda.pgc"
527 
528 if (sqlca.sqlcode < 0) exit (1);}
529 #line 256 "sqlda.pgc"
530 
531 
532 	strcpy(msg, "disconnect");
533 	{ ECPGdisconnect(__LINE__, "CURRENT");
534 #line 259 "sqlda.pgc"
535 
536 if (sqlca.sqlcode < 0) exit (1);}
537 #line 259 "sqlda.pgc"
538 
539 
540 	return (0);
541 }
542