PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pgtypeslib-nan_test.c
Go to the documentation of this file.
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 "nan_test.pgc"
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <float.h>
13 #include <math.h>
14 #include <pgtypes_numeric.h>
15 #include <decimal.h>
16 
17 
18 #line 1 "regression.h"
19 
20 
21 
22 
23 
24 
25 #line 8 "nan_test.pgc"
26 
27 
28 #ifdef WIN32
29 #if (_MSC_VER < 1800)
30 #define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF))
31 #define isnan(x) _isnan(x)
32 #endif
33 #endif /* WIN32 */
34 
35 int
36 main(void)
37 {
38  /* exec sql begin declare section */
39 
40 
41 
42 
43 
44 #line 21 "nan_test.pgc"
45  int id ;
46 
47 #line 22 "nan_test.pgc"
48  double d ;
49 
50 #line 23 "nan_test.pgc"
51  numeric * num ;
52 
53 #line 24 "nan_test.pgc"
54  char val [ 16 ] ;
55 /* exec sql end declare section */
56 #line 25 "nan_test.pgc"
57 
58 
59  ECPGdebug(1, stderr);
60  /* exec sql whenever sqlerror do sqlprint ( ) ; */
61 #line 28 "nan_test.pgc"
62 
63 
64  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
65 #line 30 "nan_test.pgc"
66 
67 if (sqlca.sqlcode < 0) sqlprint ( );}
68 #line 30 "nan_test.pgc"
69 
70 
71  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table nantest1 ( id int4 , d float8 )", ECPGt_EOIT, ECPGt_EORT);
72 #line 32 "nan_test.pgc"
73 
74 if (sqlca.sqlcode < 0) sqlprint ( );}
75 #line 32 "nan_test.pgc"
76 
77  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest1 ( id , d ) values ( 1 , 'nan' :: float8 ) , ( 2 , 'infinity' :: float8 ) , ( 3 , '-infinity' :: float8 )", ECPGt_EOIT, ECPGt_EORT);
78 #line 33 "nan_test.pgc"
79 
80 if (sqlca.sqlcode < 0) sqlprint ( );}
81 #line 33 "nan_test.pgc"
82 
83 
84  /* declare cur cursor for select id , d , d from nantest1 */
85 #line 35 "nan_test.pgc"
86 
87  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select id , d , d from nantest1", ECPGt_EOIT, ECPGt_EORT);
88 #line 36 "nan_test.pgc"
89 
90 if (sqlca.sqlcode < 0) sqlprint ( );}
91 #line 36 "nan_test.pgc"
92 
93  while (1)
94  {
95  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT,
96  ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
97  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
98  ECPGt_double,&(d),(long)1,(long)1,sizeof(double),
99  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
100  ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
101  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
102 #line 39 "nan_test.pgc"
103 
104 if (sqlca.sqlcode < 0) sqlprint ( );}
105 #line 39 "nan_test.pgc"
106 
107  if (sqlca.sqlcode)
108  break;
109  if (isnan(d))
110  printf("%d NaN '%s'\n", id, val);
111  else if (isinf(d))
112  printf("%d %sInf '%s'\n", id, (d < 0 ? "-" : "+"), val);
113 
114  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest1 ( id , d ) values ( $1 + 3 , $2 )",
115  ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
116  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
117  ECPGt_double,&(d),(long)1,(long)1,sizeof(double),
118  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
119 #line 47 "nan_test.pgc"
120 
121 if (sqlca.sqlcode < 0) sqlprint ( );}
122 #line 47 "nan_test.pgc"
123 
124  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest1 ( id , d ) values ( $1 + 6 , $2 )",
125  ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
126  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
127  ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
128  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
129 #line 48 "nan_test.pgc"
130 
131 if (sqlca.sqlcode < 0) sqlprint ( );}
132 #line 48 "nan_test.pgc"
133 
134  }
135  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
136 #line 50 "nan_test.pgc"
137 
138 if (sqlca.sqlcode < 0) sqlprint ( );}
139 #line 50 "nan_test.pgc"
140 
141 
142  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select id , d , d from nantest1", ECPGt_EOIT, ECPGt_EORT);
143 #line 52 "nan_test.pgc"
144 
145 if (sqlca.sqlcode < 0) sqlprint ( );}
146 #line 52 "nan_test.pgc"
147 
148  while (1)
149  {
150  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT,
151  ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
152  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
153  ECPGt_double,&(d),(long)1,(long)1,sizeof(double),
154  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
155  ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
156  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
157 #line 55 "nan_test.pgc"
158 
159 if (sqlca.sqlcode < 0) sqlprint ( );}
160 #line 55 "nan_test.pgc"
161 
162  if (sqlca.sqlcode)
163  break;
164  if (isinf(d))
165  printf("%d %sInf '%s'\n", id, (d < 0 ? "-" : "+"), val);
166  if (isnan(d))
167  printf("%d NaN '%s'\n", id, val);
168  }
169  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
170 #line 63 "nan_test.pgc"
171 
172 if (sqlca.sqlcode < 0) sqlprint ( );}
173 #line 63 "nan_test.pgc"
174 
175 
176  num = PGTYPESnumeric_new();
177 
178  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table nantest2 ( id int4 , d numeric )", ECPGt_EOIT, ECPGt_EORT);
179 #line 67 "nan_test.pgc"
180 
181 if (sqlca.sqlcode < 0) sqlprint ( );}
182 #line 67 "nan_test.pgc"
183 
184  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest2 ( id , d ) values ( 4 , 'nan' :: numeric )", ECPGt_EOIT, ECPGt_EORT);
185 #line 68 "nan_test.pgc"
186 
187 if (sqlca.sqlcode < 0) sqlprint ( );}
188 #line 68 "nan_test.pgc"
189 
190 
191  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select id , d , d from nantest2 where id = 4", ECPGt_EOIT,
192  ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
193  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
194  ECPGt_numeric,&(num),(long)1,(long)0,sizeof(numeric),
195  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
196  ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
197  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
198 #line 70 "nan_test.pgc"
199 
200 if (sqlca.sqlcode < 0) sqlprint ( );}
201 #line 70 "nan_test.pgc"
202 
203 
204  printf("%d %s '%s'\n", id, (num->sign == NUMERIC_NAN ? "NaN" : "not NaN"), val);
205 
206  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest2 ( id , d ) values ( 5 , $1 )",
207  ECPGt_numeric,&(num),(long)1,(long)0,sizeof(numeric),
208  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
209 #line 74 "nan_test.pgc"
210 
211 if (sqlca.sqlcode < 0) sqlprint ( );}
212 #line 74 "nan_test.pgc"
213 
214  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest2 ( id , d ) values ( 6 , $1 )",
215  ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
216  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
217 #line 75 "nan_test.pgc"
218 
219 if (sqlca.sqlcode < 0) sqlprint ( );}
220 #line 75 "nan_test.pgc"
221 
222 
223  /* declare cur1 cursor for select id , d , d from nantest2 */
224 #line 77 "nan_test.pgc"
225 
226  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur1 cursor for select id , d , d from nantest2", ECPGt_EOIT, ECPGt_EORT);
227 #line 78 "nan_test.pgc"
228 
229 if (sqlca.sqlcode < 0) sqlprint ( );}
230 #line 78 "nan_test.pgc"
231 
232  while (1)
233  {
234  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur1", ECPGt_EOIT,
235  ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
236  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
237  ECPGt_numeric,&(num),(long)1,(long)0,sizeof(numeric),
238  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
239  ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
240  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
241 #line 81 "nan_test.pgc"
242 
243 if (sqlca.sqlcode < 0) sqlprint ( );}
244 #line 81 "nan_test.pgc"
245 
246  if (sqlca.sqlcode)
247  break;
248  printf("%d %s '%s'\n", id, (num->sign == NUMERIC_NAN ? "NaN" : "not NaN"), val);
249  }
250  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur1", ECPGt_EOIT, ECPGt_EORT);
251 #line 86 "nan_test.pgc"
252 
253 if (sqlca.sqlcode < 0) sqlprint ( );}
254 #line 86 "nan_test.pgc"
255 
256 
257  PGTYPESnumeric_free(num);
258 
259  { ECPGtrans(__LINE__, NULL, "rollback");
260 #line 90 "nan_test.pgc"
261 
262 if (sqlca.sqlcode < 0) sqlprint ( );}
263 #line 90 "nan_test.pgc"
264 
265  { ECPGdisconnect(__LINE__, "CURRENT");
266 #line 91 "nan_test.pgc"
267 
268 if (sqlca.sqlcode < 0) sqlprint ( );}
269 #line 91 "nan_test.pgc"
270 
271 
272  return (0);
273 }
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
#define sqlca
Definition: sqlca.h:59
bool ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query,...)
Definition: execute.c:2030
#define ECPGdebug(X, Y)
int main(void)
void PGTYPESnumeric_free(numeric *)
Definition: numeric.c:470
numeric * PGTYPESnumeric_new(void)
Definition: numeric.c:127
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:271
int isinf(double x)
#define NUMERIC_NAN
Definition: numeric.c:167
void sqlprint(void)
Definition: error.c:336
#define NULL
Definition: c.h:229
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:199
long val
Definition: informix.c:689