Line data Source code
1 : #include <stdio.h>
2 : #include <stdlib.h>
3 : #include <float.h>
4 : #include <math.h>
5 : #include <pgtypes_numeric.h>
6 : #include <decimal.h>
7 :
8 : exec sql include ../regression;
9 :
10 : int
11 4 : main(void)
12 : {
13 : exec sql begin declare section;
14 : int id, loopcount;
15 : double d;
16 : numeric *num;
17 : char val[16];
18 : exec sql end declare section;
19 :
20 4 : ECPGdebug(1, stderr);
21 : exec sql whenever sqlerror do sqlprint();
22 :
23 4 : exec sql connect to REGRESSDB1;
24 4 :
25 4 : exec sql create table nantest1 (id int4, d float8);
26 4 : exec sql insert into nantest1 (id, d) values (1, 'nan'::float8), (2, 'infinity'::float8), (3, '-infinity'::float8);
27 4 :
28 : exec sql declare cur cursor for select id, d, d from nantest1;
29 4 : exec sql open cur;
30 16 : for (loopcount = 0; loopcount < 100; loopcount++)
31 : {
32 16 : exec sql fetch from cur into :id, :d, :val;
33 16 : if (sqlca.sqlcode)
34 4 : break;
35 12 : if (isnan(d))
36 4 : printf("%d NaN '%s'\n", id, val);
37 8 : else if (isinf(d))
38 8 : printf("%d %sInf '%s'\n", id, (d < 0 ? "-" : "+"), val);
39 :
40 12 : exec sql insert into nantest1 (id, d) values (:id + 3, :d);
41 12 : exec sql insert into nantest1 (id, d) values (:id + 6, :val);
42 12 : }
43 4 : exec sql close cur;
44 4 :
45 4 : exec sql open cur;
46 40 : for (loopcount = 0; loopcount < 100; loopcount++)
47 : {
48 40 : exec sql fetch from cur into :id, :d, :val;
49 40 : if (sqlca.sqlcode)
50 4 : break;
51 36 : if (isinf(d))
52 24 : printf("%d %sInf '%s'\n", id, (d < 0 ? "-" : "+"), val);
53 36 : if (isnan(d))
54 12 : printf("%d NaN '%s'\n", id, val);
55 : }
56 4 : exec sql close cur;
57 4 :
58 4 : num = PGTYPESnumeric_new();
59 :
60 4 : exec sql create table nantest2 (id int4, d numeric);
61 4 : exec sql insert into nantest2 (id, d) values (4, 'nan'::numeric);
62 4 :
63 4 : exec sql select id, d, d into :id, :num, :val from nantest2 where id = 4;
64 4 :
65 4 : printf("%d %s '%s'\n", id, (num->sign == NUMERIC_NAN ? "NaN" : "not NaN"), val);
66 :
67 4 : exec sql insert into nantest2 (id, d) values (5, :num);
68 4 : exec sql insert into nantest2 (id, d) values (6, :val);
69 4 :
70 : exec sql declare cur1 cursor for select id, d, d from nantest2;
71 4 : exec sql open cur1;
72 16 : for (loopcount = 0; loopcount < 100; loopcount++)
73 : {
74 16 : exec sql fetch from cur1 into :id, :num, :val;
75 16 : if (sqlca.sqlcode)
76 4 : break;
77 12 : printf("%d %s '%s'\n", id, (num->sign == NUMERIC_NAN ? "NaN" : "not NaN"), val);
78 : }
79 4 : exec sql close cur1;
80 4 :
81 4 : PGTYPESnumeric_free(num);
82 :
83 4 : exec sql rollback;
84 4 : exec sql disconnect;
85 4 :
86 4 : return 0;
87 : }
|