PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 int
29 main(void)
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 }
#define NUMERIC_NAN
Definition: numeric.c:200
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:676
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:255
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_numeric
Definition: ecpgtype.h:49
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_double
Definition: ecpgtype.h:47
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
@ ECPGt_char
Definition: ecpgtype.h:43
void sqlprint(void)
Definition: error.c:334
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:2275
long val
Definition: informix.c:689
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:160
numeric * PGTYPESnumeric_new(void)
Definition: numeric.c:42
void PGTYPESnumeric_free(numeric *var)
Definition: numeric.c:385
int main(void)
#define ECPGdebug(X, Y)
#define printf(...)
Definition: port.h:244
#define sqlca
Definition: sqlca.h:59