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

          Line data    Source code
       1             : #include <stdlib.h>
       2             : #include <string.h>
       3             : #include <stdlib.h>
       4             : #include <stdio.h>
       5             : 
       6             : exec sql include ../regression;
       7             : 
       8             : exec sql whenever sqlerror sqlprint;
       9             : 
      10             : int
      11           4 : main(void)
      12             : {
      13             : exec sql begin declare section;
      14             :     int amount[8];
      15           4 :     int increment=100;
      16             :     char name[8][8];
      17             :     char letter[8][1];
      18             :     char command[128];
      19             : exec sql end declare section;
      20             :     int i,j;
      21             : 
      22           4 :     ECPGdebug(1, stderr);
      23             : 
      24           4 :     exec sql connect to REGRESSDB1 as main;
      25           4 : 
      26           4 :     exec sql create table test (name char(8), amount int, letter char(1));
      27           4 :     exec sql commit;
      28           4 : 
      29           4 :     sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
      30           4 :     exec sql execute immediate :command;
      31           4 : 
      32           4 :     sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
      33           4 :     exec sql execute immediate :command;
      34           4 : 
      35           4 :     sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test");
      36           4 :     exec sql execute immediate :command;
      37           4 : 
      38           4 :     printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]);
      39             : 
      40           4 :     sprintf(command, "insert into test (name, amount, letter) select name, amount+$1, letter from test");
      41           4 :     exec sql prepare I from :command;
      42           4 :     exec sql execute I using :increment;
      43           4 : 
      44           4 :     printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]);
      45             : 
      46           4 :     exec sql commit;
      47           4 : 
      48           4 :     sprintf (command, "select * from test");
      49             : 
      50           4 :     exec sql prepare F from :command;
      51           4 :     exec sql declare CUR cursor for F;
      52             : 
      53           4 :     exec sql open CUR;
      54           4 :     exec sql fetch 8 in CUR into :name, :amount, :letter;
      55           4 : 
      56          36 :     for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
      57             :     {
      58          32 :         char n[8], l = letter[i][0];
      59          32 :         int a = amount[i];
      60             : 
      61          32 :         strncpy(n, name[i], 8);
      62          32 :         printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
      63             :     }
      64             : 
      65           4 :     exec sql close CUR;
      66           4 : 
      67           4 :     sprintf (command, "select * from test where ? = amount");
      68             : 
      69           4 :     exec sql prepare F from :command;
      70           4 :     exec sql declare CUR3 cursor for F;
      71             : 
      72           4 :     exec sql open CUR3 using 1;
      73           4 :     exec sql fetch in CUR3 into :name, :amount, :letter;
      74           4 : 
      75           8 :     for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
      76             :     {
      77           4 :         char n[8], l = letter[i][0];
      78           4 :         int a = amount[i];
      79             : 
      80           4 :         strncpy(n, name[i], 8);
      81           4 :         printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
      82             :     }
      83             : 
      84           4 :     exec sql close CUR3;
      85           4 :     exec sql drop table test;
      86           4 :     exec sql commit;
      87           4 :     exec sql disconnect;
      88           4 : 
      89           4 :     return 0;
      90             : }

Generated by: LCOV version 1.14