LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/compat_informix - test_informix2.pgc (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 76.6 % 47 36
Test Date: 2026-02-28 03:14:59 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit

            Line data    Source code
       1              : #include <stdio.h>
       2              : #include <stdlib.h>
       3              : #include "sqltypes.h"
       4              : 
       5              : EXEC SQL include sqlca.h;
       6              : EXEC SQL include ../regression;
       7              : EXEC SQL DEFINE MAXDBLEN 30;
       8              : 
       9              : /* Check SQLCODE, and produce a "standard error" if it's wrong! */
      10           16 : static void sql_check(const char *fn, const char *caller, int ignore)
      11              : {
      12              :   char errorstring[255];
      13              : 
      14           16 :   if (SQLCODE == ignore)
      15           14 :     return;
      16              :   else
      17              :   {
      18            2 :     if (SQLCODE != 0)
      19              :     {
      20              : 
      21            0 :       sprintf(errorstring, "**SQL error %ld doing '%s' in function '%s'. [%s]",
      22            0 :              SQLCODE, caller, fn, sqlca.sqlerrm.sqlerrmc);
      23            0 :       fprintf(stderr, "%s", errorstring);
      24            0 :       printf("%s\n", errorstring);
      25              : 
      26              :       /* attempt a ROLLBACK */
      27            0 :       EXEC SQL rollback;
      28              : 
      29            0 :       if (SQLCODE == 0)
      30              :       {
      31            0 :         sprintf(errorstring, "Rollback successful.\n");
      32              :       } else {
      33            0 :         sprintf(errorstring, "Rollback failed with code %ld.\n", SQLCODE);
      34              :       }
      35              : 
      36            0 :       fprintf(stderr, "%s", errorstring);
      37            0 :       printf("%s\n", errorstring);
      38              : 
      39            0 :       exit(1);
      40              :     }
      41              :   }
      42              : }
      43              : 
      44            2 : int main(void)
      45              : {
      46              :     EXEC SQL BEGIN DECLARE SECTION;
      47              :         int c;
      48              :         timestamp d;
      49              :         timestamp e;
      50              :         timestamp maxd;
      51              :         char dbname[30];
      52              :     EXEC SQL END DECLARE SECTION;
      53              : 
      54              :     interval *intvl;
      55              : 
      56              :     EXEC SQL whenever sqlerror stop;
      57              : 
      58            2 :     ECPGdebug(1, stderr);
      59              : 
      60            2 :     strcpy(dbname, "ecpg1_regression");
      61            2 :     EXEC SQL connect to :dbname;
      62            2 :     sql_check("main", "connect", 0);
      63              : 
      64            2 :     EXEC SQL SET DateStyle TO 'DMY';
      65            2 : 
      66            2 :     EXEC SQL create table history (customerid integer, timestamp timestamp without time zone, action_taken char(5), narrative varchar(100));
      67            2 :     sql_check("main", "create", 0);
      68              : 
      69            2 :     EXEC SQL insert into history
      70              :             (customerid, timestamp, action_taken, narrative)
      71              :             values(1, '2003-05-07 13:28:34 CEST', 'test', 'test');
      72            2 :     sql_check("main", "insert", 0);
      73              : 
      74            2 :     EXEC SQL select max(timestamp)
      75              :            into :maxd
      76              :            from history;
      77            2 :     sql_check("main", "select max", 100);
      78              : 
      79            2 :     EXEC SQL select customerid, timestamp
      80              :            into :c, :d
      81              :            from history
      82              :               where timestamp = :maxd
      83              :           limit 1;
      84            2 :     sql_check("main", "select", 0);
      85              : 
      86            2 :     printf("Read in customer %d\n", c);
      87              : 
      88            2 :     intvl = PGTYPESinterval_from_asc("1 day 2 hours 24 minutes 65 seconds", NULL);
      89            2 :     PGTYPEStimestamp_add_interval(&d, intvl, &e);
      90            2 :     free(intvl);
      91            2 :     c++;
      92              : 
      93            2 :     EXEC SQL insert into history
      94              :             (customerid, timestamp, action_taken, narrative)
      95              :             values(:c, :e, 'test', 'test');
      96            2 :     sql_check("main", "update", 0);
      97              : 
      98            2 :     EXEC SQL commit;
      99            2 : 
     100            2 :     EXEC SQL drop table history;
     101            2 :     sql_check("main", "drop", 0);
     102              : 
     103            2 :     EXEC SQL commit;
     104            2 : 
     105            2 :     EXEC SQL disconnect;
     106            2 :     sql_check("main", "disconnect", 0);
     107              : 
     108            2 :     printf("All OK!\n");
     109              : 
     110            2 :     exit(0);
     111              : 
     112              : /*
     113              :                  Table "public.history"
     114              :     Column    |            Type             | Nullable
     115              : --------------+-----------------------------+----------
     116              :  customerid   | integer                     | not null
     117              :  timestamp    | timestamp without time zone | not null
     118              :  action_taken | character(5)                | not null
     119              :  narrative    | character varying(100)      |
     120              : */
     121              : 
     122              : }
        

Generated by: LCOV version 2.0-1