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 "num_test.pgc"
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <pgtypes_numeric.h>
13 #include <decimal.h>
14 
15 
16 #line 1 "regression.h"
17 
18 
19 
20 
21 
22 
23 #line 6 "num_test.pgc"
24 
25 
26 
27 /*
28 
29 NOTE: This file has a different expect file for regression tests on MinGW32
30 
31 */
32 
33 
34 int
main(void)35 main(void)
36 {
37 	char *text="error\n";
38 	numeric *value1, *value2, *res;
39 	/* exec sql begin declare section */
40 
41 		/* = {0, 0, 0, 0, 0, NULL, NULL} ; */
42 
43 #line 22 "num_test.pgc"
44  numeric * des ;
45 /* exec sql end declare section */
46 #line 24 "num_test.pgc"
47 
48 	double d;
49 	long l1, l2;
50 	int i, min, max;
51 
52 	ECPGdebug(1, stderr);
53 	/* exec sql whenever sqlerror  do sqlprint ( ) ; */
54 #line 30 "num_test.pgc"
55 
56 
57 	{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
58 #line 32 "num_test.pgc"
59 
60 if (sqlca.sqlcode < 0) sqlprint ( );}
61 #line 32 "num_test.pgc"
62 
63 
64 	{ ECPGsetcommit(__LINE__, "off", NULL);
65 #line 34 "num_test.pgc"
66 
67 if (sqlca.sqlcode < 0) sqlprint ( );}
68 #line 34 "num_test.pgc"
69 
70 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( text char ( 5 ) , num numeric ( 14 , 7 ) )", ECPGt_EOIT, ECPGt_EORT);
71 #line 35 "num_test.pgc"
72 
73 if (sqlca.sqlcode < 0) sqlprint ( );}
74 #line 35 "num_test.pgc"
75 
76 
77 	value1 = PGTYPESnumeric_new();
78 	PGTYPESnumeric_from_int(1407, value1);
79 	text = PGTYPESnumeric_to_asc(value1, -1);
80 	printf("from int = %s\n", text);
81 	PGTYPESchar_free(text);
82 	PGTYPESnumeric_free(value1);
83 
84 	value1 = PGTYPESnumeric_from_asc("2369.7", NULL);
85 	value2 = PGTYPESnumeric_from_asc("10.0", NULL);
86 	res = PGTYPESnumeric_new();
87 	PGTYPESnumeric_add(value1, value2, res);
88 	text = PGTYPESnumeric_to_asc(res, -1);
89 	printf("add = %s\n", text);
90 	PGTYPESchar_free(text);
91 
92 	PGTYPESnumeric_sub(res, value2, res);
93 	text = PGTYPESnumeric_to_asc(res, -1);
94 	printf("sub = %s\n", text);
95 	PGTYPESchar_free(text);
96 	PGTYPESnumeric_free(value2);
97 
98 	des = PGTYPESnumeric_new();
99 	PGTYPESnumeric_copy(res, des);
100 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( text , num ) values ( 'test' , $1  )",
101 	ECPGt_numeric,&(des),(long)1,(long)0,sizeof(numeric),
102 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
103 #line 60 "num_test.pgc"
104 
105 if (sqlca.sqlcode < 0) sqlprint ( );}
106 #line 60 "num_test.pgc"
107 
108 
109 	value2 = PGTYPESnumeric_from_asc("2369.7", NULL);
110 	PGTYPESnumeric_mul(value1, value2, res);
111 	PGTYPESnumeric_free(value2);
112 
113 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select num from test where text = 'test'", ECPGt_EOIT,
114 	ECPGt_numeric,&(des),(long)1,(long)0,sizeof(numeric),
115 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
116 #line 66 "num_test.pgc"
117 
118 if (sqlca.sqlcode < 0) sqlprint ( );}
119 #line 66 "num_test.pgc"
120 
121 
122 	PGTYPESnumeric_mul(res, des, res);
123 	text = PGTYPESnumeric_to_asc(res, -1);
124 	printf("mul = %s\n", text);
125 	PGTYPESchar_free(text);
126 	PGTYPESnumeric_free(des);
127 
128 	value2 = PGTYPESnumeric_from_asc("10000", NULL);
129 	PGTYPESnumeric_div(res, value2, res);
130 	text = PGTYPESnumeric_to_asc(res, -1);
131 	PGTYPESnumeric_to_double(res, &d);
132 	printf("div = %s %e\n", text, d);
133 
134 	PGTYPESnumeric_free(value1);
135 	PGTYPESnumeric_free(value2);
136 
137 	value1 = PGTYPESnumeric_from_asc("2E7", NULL);
138 	value2 = PGTYPESnumeric_from_asc("14", NULL);
139 	i = PGTYPESnumeric_to_long(value1, &l1) | PGTYPESnumeric_to_long(value2, &l2);
140 	printf("to long(%d) = %ld %ld\n", i, l1, l2);
141 
142 	PGTYPESchar_free(text);
143 	PGTYPESnumeric_free(value1);
144 	PGTYPESnumeric_free(value2);
145 	PGTYPESnumeric_free(res);
146 
147 	/* check conversion of numeric to int */
148 	value1 = PGTYPESnumeric_from_asc("-2147483648", NULL);
149 	PGTYPESnumeric_to_int(value1, &min);
150 	printf("min int = %d\n", min);
151 	PGTYPESnumeric_free(value1);
152 
153 	value2 = PGTYPESnumeric_from_asc("2147483647", NULL);
154 	PGTYPESnumeric_to_int(value2, &max);
155 	printf("max int = %d\n", max);
156 	PGTYPESnumeric_free(value2);
157 
158 	{ ECPGtrans(__LINE__, NULL, "rollback");
159 #line 104 "num_test.pgc"
160 
161 if (sqlca.sqlcode < 0) sqlprint ( );}
162 #line 104 "num_test.pgc"
163 
164 	{ ECPGdisconnect(__LINE__, "CURRENT");
165 #line 105 "num_test.pgc"
166 
167 if (sqlca.sqlcode < 0) sqlprint ( );}
168 #line 105 "num_test.pgc"
169 
170 
171 	return (0);
172 }
173