LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/sql - desc.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 70 70 100.0 %
Date: 2024-11-21 08:14:44 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : EXEC SQL INCLUDE ../regression;
       2             : EXEC SQL WHENEVER SQLERROR SQLPRINT;
       3             : 
       4             : int
       5           4 : main(void)
       6             : {
       7             :     EXEC SQL BEGIN DECLARE SECTION;
       8           4 :     char *stmt1 = "INSERT INTO test1 VALUES ($1, $2)";
       9           4 :     char *stmt2 = "SELECT * from test1 where a = $1 and b = $2";
      10           4 :     char *stmt3 = "SELECT * from test1 where :var = a";
      11             : 
      12           4 :     int val1 = 1;
      13           4 :     char val2[4] = "one", val2output[] = "AAA";
      14           4 :     int val1output = 2, val2i = 0;
      15           4 :     int val2null = -1;
      16             :     int ind1, ind2;
      17           4 :     char desc1[8] = "outdesc";
      18             :     EXEC SQL END DECLARE SECTION;
      19             : 
      20           4 :     ECPGdebug(1, stderr);
      21             : 
      22           4 :     EXEC SQL ALLOCATE DESCRIPTOR indesc;
      23           4 :     EXEC SQL ALLOCATE DESCRIPTOR :desc1;
      24           4 : 
      25           4 :     EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = :val1;
      26           4 :     EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2i, DATA = :val2;
      27           4 : 
      28           4 :     EXEC SQL CONNECT TO REGRESSDB1;
      29           4 : 
      30           4 :     EXEC SQL CREATE TABLE test1 (a int, b text);
      31           4 :     EXEC SQL PREPARE foo1 FROM :stmt1;
      32           4 :     EXEC SQL PREPARE "Foo-1" FROM :stmt1;
      33           4 :     EXEC SQL PREPARE foo2 FROM :stmt2;
      34           4 :     EXEC SQL PREPARE foo3 FROM :stmt3;
      35           4 : 
      36           4 :     EXEC SQL EXECUTE foo1 USING SQL DESCRIPTOR indesc;
      37           4 : 
      38           4 :     EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 2;
      39           4 :     EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2null, DATA = :val2;
      40           4 : 
      41           4 :     EXEC SQL EXECUTE foo1 USING SQL DESCRIPTOR indesc;
      42           4 : 
      43           4 :     EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 3;
      44           4 :     EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val1, DATA = 'this is a long test';
      45           4 : 
      46           4 :     EXEC SQL EXECUTE "Foo-1" USING SQL DESCRIPTOR indesc;
      47           4 : 
      48           4 :     EXEC SQL DEALLOCATE "Foo-1";
      49           4 : 
      50           4 :     EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = :val1;
      51           4 :     EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2i, DATA = :val2;
      52           4 : 
      53           4 :     EXEC SQL EXECUTE foo2 USING SQL DESCRIPTOR indesc INTO SQL DESCRIPTOR :desc1;
      54           4 : 
      55           4 :     EXEC SQL GET DESCRIPTOR :desc1 VALUE 1 :val2output = DATA;
      56           4 :     printf("output = %s\n", val2output);
      57             : 
      58             :     EXEC SQL DECLARE c1 CURSOR FOR foo2;
      59           4 :     EXEC SQL OPEN c1 USING SQL DESCRIPTOR indesc;
      60           4 : 
      61           4 :     EXEC SQL FETCH next FROM c1 INTO :val1output:ind1, :val2output:ind2;
      62           4 :     printf("val1=%d (ind1: %d) val2=%s (ind2: %d)\n",
      63             :         val1output, ind1, val2output, ind2);
      64             : 
      65           4 :     EXEC SQL CLOSE c1;
      66           4 : 
      67           4 :     EXEC SQL SET DESCRIPTOR indesc COUNT = 1;
      68           4 :     EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 2;
      69           4 : 
      70             :     EXEC SQL DECLARE c2 CURSOR FOR foo3;
      71           4 :     EXEC SQL OPEN c2 USING SQL DESCRIPTOR indesc;
      72           4 : 
      73           4 :     EXEC SQL FETCH next FROM c2 INTO :val1output, :val2output :val2i;
      74           4 :     printf("val1=%d val2=%s\n", val1output, val2i ? "null" : val2output);
      75             : 
      76           4 :     EXEC SQL CLOSE c2;
      77           4 : 
      78           4 :     EXEC SQL SELECT * INTO :val1output, :val2output:val2i FROM test1 where a = 3;
      79           4 :     printf("val1=%d val2=%c%c%c%c warn=%c truncate=%d\n", val1output, val2output[0], val2output[1], val2output[2], val2output[3], sqlca.sqlwarn[0], val2i);
      80             : 
      81           4 :     EXEC SQL DROP TABLE test1;
      82           4 :     EXEC SQL DEALLOCATE ALL;
      83           4 :     EXEC SQL DISCONNECT;
      84           4 : 
      85           4 :     EXEC SQL DEALLOCATE DESCRIPTOR indesc;
      86           4 :     EXEC SQL DEALLOCATE DESCRIPTOR :desc1;
      87           4 : 
      88           4 :     return 0;
      89             : }

Generated by: LCOV version 1.14