3
#include <pgtypes_numeric.h>
6
exec sql include ../regression;
11
NOTE: This file has a different expect file for regression tests on MinGW32
20
numeric *value1, *value2, *res;
21
exec sql begin declare section;
23
/* = {0, 0, 0, 0, 0, NULL, NULL} ; */
24
exec sql end declare section;
30
exec sql whenever sqlerror do sqlprint();
32
exec sql connect to REGRESSDB1;
34
exec sql set autocommit = off;
35
exec sql create table test (text char(5), num numeric(14,7));
37
value1 = PGTYPESnumeric_new();
38
PGTYPESnumeric_from_int(1407, value1);
39
text = PGTYPESnumeric_to_asc(value1, -1);
40
printf("from int = %s\n", text);
42
PGTYPESnumeric_free(value1);
44
value1 = PGTYPESnumeric_from_asc("2369.7", NULL);
45
value2 = PGTYPESnumeric_from_asc("10.0", NULL);
46
res = PGTYPESnumeric_new();
47
PGTYPESnumeric_add(value1, value2, res);
48
text = PGTYPESnumeric_to_asc(res, -1);
49
printf("add = %s\n", text);
52
PGTYPESnumeric_sub(res, value2, res);
53
text = PGTYPESnumeric_to_asc(res, -1);
54
printf("sub = %s\n", text);
56
PGTYPESnumeric_free(value2);
58
des = PGTYPESnumeric_new();
59
PGTYPESnumeric_copy(res, des);
60
exec sql insert into test (text, num) values ('test', :des);
62
value2 = PGTYPESnumeric_from_asc("2369.7", NULL);
63
PGTYPESnumeric_mul(value1, value2, res);
64
PGTYPESnumeric_free(value2);
66
exec sql select num into :des from test where text = 'test';
68
PGTYPESnumeric_mul(res, des, res);
69
text = PGTYPESnumeric_to_asc(res, -1);
70
printf("mul = %s\n", text);
72
PGTYPESnumeric_free(des);
74
value2 = PGTYPESnumeric_from_asc("10000", NULL);
75
PGTYPESnumeric_div(res, value2, res);
76
text = PGTYPESnumeric_to_asc(res, -1);
77
PGTYPESnumeric_to_double(res, &d);
78
printf("div = %s %e\n", text, d);
80
value1 = PGTYPESnumeric_from_asc("2E7", NULL);
81
value2 = PGTYPESnumeric_from_asc("14", NULL);
82
i = PGTYPESnumeric_to_long(value1, &l1) | PGTYPESnumeric_to_long(value2, &l2);
83
printf("to long(%d) = %ld %ld\n", i, l1, l2);
86
PGTYPESnumeric_free(value1);
87
PGTYPESnumeric_free(value2);
88
PGTYPESnumeric_free(res);