LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/preproc - whenever.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 12beta2 Lines: 39 39 100.0 %
Date: 2019-06-18 07:06:57 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include <stdlib.h>
       2             : 
       3             : exec sql include ../regression;
       4             : 
       5             : exec sql whenever sqlerror sqlprint;
       6             : 
       7           4 : static void print(const char *msg)
       8             : {
       9           4 :         fprintf(stderr, "Error in statement '%s':\n", msg);
      10           4 :         sqlprint();
      11           4 : }
      12             : 
      13           4 : static void print2(void)
      14             : {
      15           4 :         fprintf(stderr, "Found another error\n");
      16           4 :         sqlprint();
      17           4 : }
      18             : 
      19           4 : static void warn(void)
      20             : {
      21           4 :         fprintf(stderr, "Warning: At least one column was truncated\n");
      22           4 : }
      23             : 
      24           4 : int main(void)
      25             : {
      26             :     exec sql int i;
      27             :     exec sql char c[6];
      28             : 
      29           4 :     ECPGdebug(1, stderr);
      30             : 
      31           4 :     exec sql connect to REGRESSDB1;
      32           4 :     exec sql create table test(i int, c char(10));
      33           4 :     exec sql insert into test values(1, 'abcdefghij');
      34           4 : 
      35             :     exec sql whenever sqlwarning do warn();
      36           4 :     exec sql select * into :i, :c from test;
      37           4 :     exec sql rollback;
      38           4 : 
      39           4 :     exec sql select * into :i from nonexistent;
      40           4 :     exec sql rollback;
      41           4 : 
      42             :     exec sql whenever sqlerror do print("select");
      43           4 :     exec sql select * into :i from nonexistent;
      44           4 :     exec sql rollback;
      45           4 : 
      46             :     exec sql whenever sqlerror call print2();
      47           4 :     exec sql select * into :i from nonexistent;
      48           4 :     exec sql rollback;
      49           4 : 
      50             :     exec sql whenever sqlerror continue;
      51           4 :     exec sql select * into :i from nonexistent;
      52           4 :     exec sql rollback;
      53           4 : 
      54             :     exec sql whenever sqlerror goto error;
      55           4 :     exec sql select * into :i from nonexistent;
      56           4 :     printf("Should not be reachable\n");
      57             : 
      58             :     error:
      59           4 :     exec sql rollback;
      60           4 : 
      61             :     exec sql whenever sqlerror stop;
      62             :     /* This cannot fail, thus we don't get an exit value not equal 0. */
      63             :     /* However, it still test the precompiler output. */
      64           4 :     exec sql select 1 into :i;
      65           4 :     exec sql rollback;
      66           4 :     exit (0);
      67             : }

Generated by: LCOV version 1.13