~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/interfaces/ecpg/test/num_test.pgc

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <pgtypes_numeric.h>
 
3
#include <decimal.h>
 
4
 
 
5
int
 
6
main()
 
7
{
 
8
        char *text="error\n";
 
9
        numeric *value1, *value2, *res;
 
10
        exec sql begin declare section;
 
11
                numeric(14,7) des = {0, 0, 0, 0, 0, NULL, NULL} ;
 
12
        exec sql end declare section;
 
13
        double d;
 
14
        FILE *dbgs;
 
15
        
 
16
        if ((dbgs = fopen("log", "w")) != NULL)
 
17
                 ECPGdebug(1, dbgs);
 
18
        exec sql whenever sqlerror do sqlprint();
 
19
 
 
20
        exec sql connect to mm;
 
21
        exec sql create table test (text char(5), num numeric(14,7));
 
22
        
 
23
        value1 = PGTYPESnumeric_new();
 
24
        PGTYPESnumeric_from_int(1407, value1);
 
25
        text = PGTYPESnumeric_to_asc(value1, -1);
 
26
        printf("long = %s\n", text);
 
27
                
 
28
        value1 = PGTYPESnumeric_from_asc("2369.7", NULL);
 
29
        value2 = PGTYPESnumeric_from_asc("10.0", NULL);
 
30
        res = PGTYPESnumeric_new();
 
31
        PGTYPESnumeric_add(value1, value2, res);
 
32
        text = PGTYPESnumeric_to_asc(res, -1);
 
33
        printf("add = %s\n", text);
 
34
        
 
35
        PGTYPESnumeric_sub(res, value2, res);
 
36
        text = PGTYPESnumeric_to_asc(res, -1);
 
37
        printf("sub = %s\n", text);
 
38
                
 
39
        PGTYPESnumeric_copy(res, &des);
 
40
        exec sql insert into test (text, num) values ('test', :des);
 
41
        
 
42
        value2 = PGTYPESnumeric_from_asc("2369.7", NULL);
 
43
        PGTYPESnumeric_mul(value1, value2, res);
 
44
 
 
45
        exec sql select num into :des from test where text = 'test';
 
46
        
 
47
        PGTYPESnumeric_mul(res, &des, res);
 
48
        text = PGTYPESnumeric_to_asc(res, -1);
 
49
        printf("mul = %s\n", text);
 
50
 
 
51
        value2 = PGTYPESnumeric_from_asc("10000", NULL);
 
52
        PGTYPESnumeric_div(res, value2, res);
 
53
        text = PGTYPESnumeric_to_asc(res, -1);
 
54
        PGTYPESnumeric_to_double(res, &d);
 
55
        printf("div = %s %e\n", text, d);
 
56
 
 
57
        exec sql rollback;
 
58
        exec sql disconnect;
 
59
 
 
60
        if (dbgs != NULL)
 
61
                fclose(dbgs);
 
62
                
 
63
        return (0);
 
64
}
 
65