LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/sql - array.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 63 63 100.0 %
Date: 2019-11-13 22:07:24 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include <locale.h>
       2             : #include <string.h>
       3             : #include <stdlib.h>
       4             : 
       5             : #include <pgtypes_date.h>
       6             : #include <pgtypes_interval.h>
       7             : #include <pgtypes_numeric.h>
       8             : #include <pgtypes_timestamp.h>
       9             : 
      10             : exec sql whenever sqlerror sqlprint;
      11             : 
      12             : exec sql include sqlca;
      13             : exec sql include ../regression;
      14             : 
      15             : int
      16           4 : main (void)
      17             : {
      18             : EXEC SQL BEGIN DECLARE SECTION;
      19           4 :     int i = 1, j;
      20           4 :     int *did = &i;
      21           4 :     short a[10] = {9,8,7,6,5,4,3,2,1,0};
      22             :     timestamp ts[10];
      23             :     date d[10];
      24             :     interval in[10];
      25             :     numeric n[10];
      26           4 :     char text[25] = "klmnopqrst";
      27           4 :     char *t = (char *)malloc(11);
      28             :     double f;
      29             : EXEC SQL END DECLARE SECTION;
      30             : 
      31           4 :     strcpy(t, "0123456789");
      32           4 :     setlocale(LC_ALL, "C");
      33             : 
      34           4 :     ECPGdebug(1, stderr);
      35             : 
      36          44 :     for (j = 0; j < 10; j++) {
      37             :         char str[28];
      38             :         numeric *value;
      39             :         interval *inter;
      40             : 
      41          40 :         sprintf(str, "2000-1-1 0%d:00:00", j);
      42          40 :         ts[j] = PGTYPEStimestamp_from_asc(str, NULL);
      43          40 :         sprintf(str, "2000-1-1%d\n", j);
      44          40 :         d[j] = PGTYPESdate_from_asc(str, NULL);
      45          40 :         sprintf(str, "%d hours", j+10);
      46          40 :         inter = PGTYPESinterval_from_asc(str, NULL);
      47          40 :         in[j] = *inter;
      48          40 :         value = PGTYPESnumeric_new();
      49          40 :         PGTYPESnumeric_from_int(j, value);
      50          40 :         n[j] = *value;
      51             :     }
      52             : 
      53           4 :         EXEC SQL CONNECT TO REGRESSDB1;
      54           4 : 
      55           4 :     EXEC SQL SET AUTOCOMMIT = ON;
      56           4 : 
      57           4 :     EXEC SQL BEGIN WORK;
      58           4 : 
      59           4 :     EXEC SQL CREATE TABLE test (f float, i int, a int[10], text char(10), ts timestamp[10], n numeric[10], d date[10], inter interval[10]);
      60           4 : 
      61           4 :     EXEC SQL INSERT INTO test(f,i,a,text,ts,n,d,inter) VALUES(404.90,3,'{0,1,2,3,4,5,6,7,8,9}','abcdefghij',:ts,:n,:d,:in);
      62           4 : 
      63           4 :     EXEC SQL INSERT INTO test(f,i,a,text,ts,n,d,inter) VALUES(140787.0,2,:a,:text,:ts,:n,:d,:in);
      64           4 : 
      65           4 :     EXEC SQL INSERT INTO test(f,i,a,text,ts,n,d,inter) VALUES(14.07,:did,:a,:t,:ts,:n,:d,:in);
      66           4 : 
      67           4 :     EXEC SQL COMMIT;
      68           4 : 
      69          44 :     for (j = 0; j < 10; j++) {
      70          40 :         ts[j] = PGTYPEStimestamp_from_asc("1900-01-01 00:00:00", NULL);
      71          40 :         d[j] = PGTYPESdate_from_asc("1900-01-01", NULL);
      72          40 :         in[j] = *PGTYPESinterval_new();
      73          40 :         n[j] = *PGTYPESnumeric_new();
      74             :     }
      75           4 :     EXEC SQL BEGIN WORK;
      76           4 : 
      77           4 :     EXEC SQL SELECT f,text
      78             :          INTO :f,:text
      79             :          FROM test
      80             :          WHERE i = 1;
      81           4 : 
      82           4 :     printf("Found f=%f text=%10.10s\n", f, text);
      83             : 
      84           4 :     f=140787;
      85           4 :     EXEC SQL SELECT a,text,ts,n,d,inter
      86             :      INTO :a,:t,:ts,:n,:d,:in
      87             :      FROM test
      88             :      WHERE f = :f;
      89           4 : 
      90          44 :     for (i = 0; i < 10; i++)
      91          40 :         printf("Found a[%d] = %d ts[%d] = %s n[%d] = %s d[%d] = %s in[%d] = %s\n", i, a[i], i, PGTYPEStimestamp_to_asc(ts[i]), i, PGTYPESnumeric_to_asc(&(n[i]), -1), i, PGTYPESdate_to_asc(d[i]), i, PGTYPESinterval_to_asc(&(in[i])));
      92             : 
      93           4 :     printf("Found text=%10.10s\n", t);
      94             : 
      95           4 :     EXEC SQL SELECT a
      96             :      INTO :text
      97             :      FROM test
      98             :      WHERE f = :f;
      99           4 : 
     100           4 :     printf("Found text=%s\n", text);
     101             : 
     102           4 :     EXEC SQL DROP TABLE test;
     103           4 : 
     104           4 :     EXEC SQL COMMIT;
     105           4 : 
     106           4 :     EXEC SQL DISCONNECT;
     107           4 : 
     108           4 :     free(t);
     109             : 
     110           4 :     return 0;
     111             : }

Generated by: LCOV version 1.13