LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/pgtypeslib - num_test.pgc (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 100.0 % 69 69
Test Date: 2026-07-25 22:15:46 Functions: 100.0 % 1 1
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 50.0 % 14 7

             Branch data     Line data    Source code
       1                 :             : #include <stdio.h>
       2                 :             : #include <stdlib.h>
       3                 :             : #include <pgtypes_numeric.h>
       4                 :             : #include <decimal.h>
       5                 :             : 
       6                 :             : exec sql include ../regression;
       7                 :             : 
       8                 :             : exec sql include ../printf_hack;
       9                 :             : 
      10                 :             : 
      11                 :             : int
      12                 :           2 : main(void)
      13                 :             : {
      14                 :           2 :     char *text="error\n";
      15                 :             :     numeric *value1, *value2, *res;
      16                 :             :     exec sql begin declare section;
      17                 :             :         numeric(14,7) *des;
      18                 :             :         /* = {0, 0, 0, 0, 0, NULL, NULL} ; */
      19                 :             :     exec sql end declare section;
      20                 :             :     double d;
      21                 :             :     long l1, l2;
      22                 :             :     int i, min, max;
      23                 :             : 
      24                 :           2 :     ECPGdebug(1, stderr);
      25                 :             :     exec sql whenever sqlerror do sqlprint();
      26                 :             : 
      27                 :           2 :     exec sql connect to REGRESSDB1;
      28         [ -  + ]:           2 : 
      29                 :           2 :     exec sql set autocommit = off;
      30         [ -  + ]:           2 :     exec sql create table test (text char(5), num numeric(14,7));
      31         [ -  + ]:           2 : 
      32                 :           2 :     value1 = PGTYPESnumeric_new();
      33                 :           2 :     PGTYPESnumeric_from_int(1407, value1);
      34                 :           2 :     text = PGTYPESnumeric_to_asc(value1, -1);
      35                 :           2 :     printf("from int = %s\n", text);
      36                 :           2 :     PGTYPESchar_free(text);
      37                 :           2 :     PGTYPESnumeric_free(value1);
      38                 :             : 
      39                 :           2 :     value1 = PGTYPESnumeric_from_asc("2369.7", NULL);
      40                 :           2 :     value2 = PGTYPESnumeric_from_asc("10.0", NULL);
      41                 :           2 :     res = PGTYPESnumeric_new();
      42                 :           2 :     PGTYPESnumeric_add(value1, value2, res);
      43                 :           2 :     text = PGTYPESnumeric_to_asc(res, -1);
      44                 :           2 :     printf("add = %s\n", text);
      45                 :           2 :     PGTYPESchar_free(text);
      46                 :             : 
      47                 :           2 :     PGTYPESnumeric_sub(res, value2, res);
      48                 :           2 :     text = PGTYPESnumeric_to_asc(res, -1);
      49                 :           2 :     printf("sub = %s\n", text);
      50                 :           2 :     PGTYPESchar_free(text);
      51                 :           2 :     PGTYPESnumeric_free(value2);
      52                 :             : 
      53                 :           2 :     des = PGTYPESnumeric_new();
      54                 :           2 :     PGTYPESnumeric_copy(res, des);
      55                 :           2 :     exec sql insert into test (text, num) values ('test', :des);
      56         [ -  + ]:           2 : 
      57                 :           2 :     value2 = PGTYPESnumeric_from_asc("2369.7", NULL);
      58                 :           2 :     PGTYPESnumeric_mul(value1, value2, res);
      59                 :           2 :     PGTYPESnumeric_free(value2);
      60                 :             : 
      61                 :           2 :     exec sql select num into :des from test where text = 'test';
      62         [ -  + ]:           2 : 
      63                 :           2 :     PGTYPESnumeric_mul(res, des, res);
      64                 :           2 :     text = PGTYPESnumeric_to_asc(res, -1);
      65                 :           2 :     printf("mul = %s\n", text);
      66                 :           2 :     PGTYPESchar_free(text);
      67                 :           2 :     PGTYPESnumeric_free(des);
      68                 :             : 
      69                 :           2 :     value2 = PGTYPESnumeric_from_asc("10000", NULL);
      70                 :           2 :     PGTYPESnumeric_div(res, value2, res);
      71                 :           2 :     text = PGTYPESnumeric_to_asc(res, -1);
      72                 :           2 :     PGTYPESnumeric_to_double(res, &d);
      73                 :           2 :     printf("div = %s ", text);
      74                 :           2 :     print_double(d);
      75                 :           2 :     printf("\n");
      76                 :             : 
      77                 :           2 :     PGTYPESnumeric_free(value1);
      78                 :           2 :     PGTYPESnumeric_free(value2);
      79                 :             : 
      80                 :           2 :     value1 = PGTYPESnumeric_from_asc("2E7", NULL);
      81                 :           2 :     value2 = PGTYPESnumeric_from_asc("14", NULL);
      82                 :           2 :     i = PGTYPESnumeric_to_long(value1, &l1) | PGTYPESnumeric_to_long(value2, &l2);
      83                 :           2 :     printf("to long(%d) = %ld %ld\n", i, l1, l2);
      84                 :             : 
      85                 :           2 :     PGTYPESchar_free(text);
      86                 :           2 :     PGTYPESnumeric_free(value1);
      87                 :           2 :     PGTYPESnumeric_free(value2);
      88                 :           2 :     PGTYPESnumeric_free(res);
      89                 :             : 
      90                 :             :     /* check conversion of numeric to int */
      91                 :           2 :     value1 = PGTYPESnumeric_from_asc("-2147483648", NULL);
      92                 :           2 :     PGTYPESnumeric_to_int(value1, &min);
      93                 :           2 :     printf("min int = %d\n", min);
      94                 :           2 :     PGTYPESnumeric_free(value1);
      95                 :             : 
      96                 :           2 :     value2 = PGTYPESnumeric_from_asc("2147483647", NULL);
      97                 :           2 :     PGTYPESnumeric_to_int(value2, &max);
      98                 :           2 :     printf("max int = %d\n", max);
      99                 :           2 :     PGTYPESnumeric_free(value2);
     100                 :             : 
     101                 :           2 :     exec sql rollback;
     102         [ -  + ]:           2 :     exec sql disconnect;
     103         [ -  + ]:           2 : 
     104                 :           2 :     return 0;
     105                 :             : }
        

Generated by: LCOV version 2.0-1