PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

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

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

Referenced by main().

Function Documentation

int main ( void  )

Definition at line 34 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(), NULL, NUMERIC_NAN, PGTYPESnumeric_free(), PGTYPESnumeric_new(), numeric::sign, sqlca, sqlprint(), and val.

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