LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/sql - array.pgc (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 100.0 % 63 63
Test Date: 2026-03-11 10:16:42 Functions: 100.0 % 1 1
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            2 : main (void)
      17              : {
      18              : EXEC SQL BEGIN DECLARE SECTION;
      19            2 :     int i = 1, j;
      20            2 :     int *did = &i;
      21            2 :     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            2 :     char text[25] = "klmnopqrst";
      27            2 :     char *t = (char *)malloc(11);
      28              :     double f;
      29              : EXEC SQL END DECLARE SECTION;
      30              : 
      31            2 :     strcpy(t, "0123456789");
      32            2 :     setlocale(LC_ALL, "C");
      33              : 
      34            2 :     ECPGdebug(1, stderr);
      35              : 
      36           22 :     for (j = 0; j < 10; j++) {
      37              :         char str[28];
      38              :         numeric *value;
      39              :         interval *inter;
      40              : 
      41           20 :         sprintf(str, "2000-1-1 0%d:00:00", j);
      42           20 :         ts[j] = PGTYPEStimestamp_from_asc(str, NULL);
      43           20 :         sprintf(str, "2000-1-1%d\n", j);
      44           20 :         d[j] = PGTYPESdate_from_asc(str, NULL);
      45           20 :         sprintf(str, "%d hours", j+10);
      46           20 :         inter = PGTYPESinterval_from_asc(str, NULL);
      47           20 :         in[j] = *inter;
      48           20 :         value = PGTYPESnumeric_new();
      49           20 :         PGTYPESnumeric_from_int(j, value);
      50           20 :         n[j] = *value;
      51              :     }
      52              : 
      53            2 :         EXEC SQL CONNECT TO REGRESSDB1;
      54            2 : 
      55            2 :     EXEC SQL SET AUTOCOMMIT = ON;
      56            2 : 
      57            2 :     EXEC SQL BEGIN WORK;
      58            2 : 
      59            2 :     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            2 : 
      61            2 :     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            2 : 
      63            2 :     EXEC SQL INSERT INTO test(f,i,a,text,ts,n,d,inter) VALUES(140787.0,2,:a,:text,:ts,:n,:d,:in);
      64            2 : 
      65            2 :     EXEC SQL INSERT INTO test(f,i,a,text,ts,n,d,inter) VALUES(14.07,:did,:a,:t,:ts,:n,:d,:in);
      66            2 : 
      67            2 :     EXEC SQL COMMIT;
      68            2 : 
      69           22 :     for (j = 0; j < 10; j++) {
      70           20 :         ts[j] = PGTYPEStimestamp_from_asc("1900-01-01 00:00:00", NULL);
      71           20 :         d[j] = PGTYPESdate_from_asc("1900-01-01", NULL);
      72           20 :         in[j] = *PGTYPESinterval_new();
      73           20 :         n[j] = *PGTYPESnumeric_new();
      74              :     }
      75            2 :     EXEC SQL BEGIN WORK;
      76            2 : 
      77            2 :     EXEC SQL SELECT f,text
      78              :          INTO :f,:text
      79              :          FROM test
      80              :          WHERE i = 1;
      81            2 : 
      82            2 :     printf("Found f=%f text=%10.10s\n", f, text);
      83              : 
      84            2 :     f=140787;
      85            2 :     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            2 : 
      90           22 :     for (i = 0; i < 10; i++)
      91           20 :         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            2 :     printf("Found text=%10.10s\n", t);
      94              : 
      95            2 :     EXEC SQL SELECT a
      96              :      INTO :text
      97              :      FROM test
      98              :      WHERE f = :f;
      99            2 : 
     100            2 :     printf("Found text=%s\n", text);
     101              : 
     102            2 :     EXEC SQL DROP TABLE test;
     103            2 : 
     104            2 :     EXEC SQL COMMIT;
     105            2 : 
     106            2 :     EXEC SQL DISCONNECT;
     107            2 : 
     108            2 :     free(t);
     109              : 
     110            2 :     return 0;
     111              : }
        

Generated by: LCOV version 2.0-1