LCOV - differential code coverage report
Current view: top level - src/interfaces/ecpg/test/compat_informix - test_informix2.pgc (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 76.6 % 47 36 11 36
Current Date: 2023-04-08 15:15:32 Functions: 100.0 % 2 2 2
Baseline: 15
Baseline Date: 2023-04-08 15:09:40
Legend: Lines: hit not hit

           TLA  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 CBC           8 : static void sql_check(const char *fn, const char *caller, int ignore)
      11                 : {
      12                 :   char errorstring[255];
      13                 : 
      14               8 :   if (SQLCODE == ignore)
      15               7 :     return;
      16                 :   else
      17                 :   {
      18               1 :     if (SQLCODE != 0)
      19                 :     {
      20                 : 
      21 UBC           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 CBC           1 : 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               1 :     ECPGdebug(1, stderr);
      59                 : 
      60               1 :     strcpy(dbname, "ecpg1_regression");
      61               1 :     EXEC SQL connect to :dbname;
      62               1 :     sql_check("main", "connect", 0);
      63                 : 
      64               1 :     EXEC SQL SET DateStyle TO 'DMY';
      65               1 : 
      66               1 :     EXEC SQL create table history (customerid integer, timestamp timestamp without time zone, action_taken char(5), narrative varchar(100));
      67               1 :     sql_check("main", "create", 0);
      68                 : 
      69               1 :     EXEC SQL insert into history
      70                 :             (customerid, timestamp, action_taken, narrative)
      71                 :             values(1, '2003-05-07 13:28:34 CEST', 'test', 'test');
      72               1 :     sql_check("main", "insert", 0);
      73                 : 
      74               1 :     EXEC SQL select max(timestamp)
      75                 :            into :maxd
      76                 :            from history;
      77               1 :     sql_check("main", "select max", 100);
      78                 : 
      79               1 :     EXEC SQL select customerid, timestamp
      80                 :            into :c, :d
      81                 :            from history
      82                 :               where timestamp = :maxd
      83                 :           limit 1;
      84               1 :     sql_check("main", "select", 0);
      85                 : 
      86               1 :     printf("Read in customer %d\n", c);
      87                 : 
      88               1 :     intvl = PGTYPESinterval_from_asc("1 day 2 hours 24 minutes 65 seconds", NULL);
      89               1 :     PGTYPEStimestamp_add_interval(&d, intvl, &e);
      90               1 :     free(intvl);
      91               1 :     c++;
      92                 : 
      93               1 :     EXEC SQL insert into history
      94                 :             (customerid, timestamp, action_taken, narrative)
      95                 :             values(:c, :e, 'test', 'test');
      96               1 :     sql_check("main", "update", 0);
      97                 : 
      98               1 :     EXEC SQL commit;
      99               1 : 
     100               1 :     EXEC SQL drop table history;
     101               1 :     sql_check("main", "drop", 0);
     102                 : 
     103               1 :     EXEC SQL commit;
     104               1 : 
     105               1 :     EXEC SQL disconnect;
     106               1 :     sql_check("main", "disconnect", 0);
     107                 : 
     108               1 :     printf("All OK!\n");
     109                 : 
     110               1 :     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 v1.16-55-g56c0a2a