PostgreSQL Source Code  git master
pgtypeslib-nan_test.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <math.h>
#include <pgtypes_numeric.h>
#include <decimal.h>
Include dependency graph for pgtypeslib-nan_test.c:

Go to the source code of this file.

Macros

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 

Functions

int main (void)
 

Macro Definition Documentation

◆ ECPGdebug

#define ECPGdebug (   X,
 
)    ECPGdebug((X)+100,(Y))

Definition at line 7 of file pgtypeslib-nan_test.c.

Referenced by main().

Function Documentation

◆ main()

int main ( void  )

Definition at line 29 of file pgtypeslib-nan_test.c.

References ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGst_normal, ECPGt_char, ECPGt_double, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, ECPGt_numeric, ECPGtrans(), isinf(), NUMERIC_NAN, PGTYPESnumeric_free(), PGTYPESnumeric_new(), printf, numeric::sign, sqlca, sqlprint(), and val.

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