LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/sql - prepareas.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 158 158 100.0 %
Date: 2019-11-15 23:07:02 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include <stdlib.h>
       2             : #include <string.h>
       3             : #include <stdio.h>
       4             : 
       5             : exec sql include ../regression;
       6             : exec sql whenever sqlerror sqlprint;
       7             : 
       8             : static void
       9          68 : check_result_of_insert(void)
      10             : {
      11             :     exec sql begin declare section;
      12          68 :     int ivar1 = 0, ivar2 = 0;
      13             :     exec sql end declare section;
      14             : 
      15          68 :     exec sql select c1,c2 into :ivar1,:ivar2 from test;
      16          68 :     printf("%d %d\n", ivar1, ivar2);
      17          68 : }
      18             : 
      19           4 : int main(void)
      20             : {
      21             :     exec sql begin declare section;
      22           4 :     int ivar1 = 1, ivar2 = 2;
      23             :     char v_include_dq_name[16], v_include_ws_name[16], v_normal_name[16], v_query[64];
      24             :     exec sql end declare section;
      25             : 
      26           4 :     strcpy(v_normal_name, "normal_name");
      27           4 :     strcpy(v_include_dq_name, "include_\"_name");
      28           4 :     strcpy(v_include_ws_name, "include_ _name");
      29           4 :     strcpy(v_query, "insert into test values(?,?)");
      30             : 
      31             :     /*
      32             :      * preparing for test
      33             :      */
      34           4 :     exec sql connect to REGRESSDB1;
      35           4 :     exec sql begin;
      36           4 :     exec sql create table test (c1 int, c2 int);
      37           4 :     exec sql commit work;
      38           4 :     exec sql begin;
      39           4 : 
      40             :     /*
      41             :      * Non dynamic statement
      42             :      */
      43           4 :     exec sql truncate test;
      44           4 :     printf("+++++ Test for prepnormal +++++\n");
      45           4 :     printf("insert into test values(:ivar1,:ivar2)\n");
      46           4 :     exec sql insert into test values(:ivar1,:ivar2);
      47           4 :     check_result_of_insert();
      48             : 
      49           4 :     exec sql truncate test;
      50           4 :     printf("+++++ Test for execute immediate +++++\n");
      51           4 :     printf("execute immediate \"insert into test values(1,2)\"\n");
      52           4 :     exec sql execute immediate "insert into test values(1,2)";
      53           4 :     check_result_of_insert();
      54             : 
      55             :     /*
      56             :      * PREPARE FROM
      57             :      */
      58           4 :     exec sql truncate test;
      59           4 :     printf("+++++ Test for PREPARE ident FROM CString +++++\n");
      60           4 :     printf("prepare ident_name from \"insert into test values(?,?)\"\n");
      61           4 :     exec sql prepare ident_name from "insert into test values(?,?)";
      62           4 :     printf("execute ident_name using :ivar1,:ivar2\n");
      63           4 :     exec sql execute ident_name using :ivar1,:ivar2;
      64           4 :     check_result_of_insert();
      65             : 
      66           4 :     exec sql truncate test;
      67           4 :     printf("+++++ Test for PREPARE char_variable_normal_name FROM char_variable +++++\n");
      68           4 :     printf("prepare :v_normal_name from :v_query\n");
      69           4 :     exec sql prepare :v_normal_name from :v_query;
      70           4 :     printf("execute :v_normal_name using :ivar1,:ivar2\n");
      71           4 :     exec sql execute :v_normal_name using :ivar1,:ivar2;
      72           4 :     check_result_of_insert();
      73             : 
      74           4 :     exec sql truncate test;
      75           4 :     printf("+++++ Test for PREPARE char_variable_inc_dq_name FROM char_variable +++++\n");
      76           4 :     printf("prepare :v_include_dq_name from :v_query\n");
      77           4 :     exec sql prepare :v_include_dq_name from :v_query;
      78           4 :     printf("execute :v_include_dq_name using :ivar1,:ivar2\n");
      79           4 :     exec sql execute :v_include_dq_name using :ivar1,:ivar2;
      80           4 :     check_result_of_insert();
      81             : 
      82           4 :     exec sql truncate test;
      83           4 :     printf("+++++ Test for PREPARE char_variable_inc_ws_name FROM char_variable +++++\n");
      84           4 :     printf("prepare :v_include_ws_name from :v_query\n");
      85           4 :     exec sql prepare :v_include_ws_name from :v_query;
      86           4 :     printf("execute :v_include_ws_name using :ivar1,:ivar2\n");
      87           4 :     exec sql execute :v_include_ws_name using :ivar1,:ivar2;
      88           4 :     check_result_of_insert();
      89             : 
      90           4 :     exec sql truncate test;
      91           4 :     printf("+++++ Test for PREPARE CString_inc_ws_name FROM char_variable +++++\n");
      92           4 :     printf("prepare \"include_ _name\" from :v_query\n");
      93           4 :     exec sql prepare "include_ _name" from :v_query;
      94           4 :     printf("exec sql execute \"include_ _name\" using :ivar1,:ivar2\n");
      95           4 :     exec sql execute "include_ _name" using :ivar1,:ivar2;
      96           4 :     check_result_of_insert();
      97             : 
      98           4 :     exec sql truncate test;
      99           4 :     printf("+++++ Test for PREPARE CString_normal_name FROM char_variable +++++\n");
     100           4 :     printf("prepare \"norma_name\" from :v_query\n");
     101           4 :     exec sql prepare "normal_name" from :v_query;
     102           4 :     printf("exec sql execute \"normal_name\" using :ivar1,:ivar2\n");
     103           4 :     exec sql execute "normal_name" using :ivar1,:ivar2;
     104           4 :     check_result_of_insert();
     105             : 
     106             :     /*
     107             :      * PREPARE AS
     108             :      */
     109           4 :     exec sql deallocate "ident_name";
     110           4 :     exec sql deallocate "normal_name";
     111           4 :     exec sql deallocate "include_ _name";
     112           4 : 
     113           4 :     exec sql truncate test;
     114           4 :     printf("+++++ Test for PREPARE ident(typelist) AS +++++\n");
     115           4 :     printf("prepare ident_name(int,int) as insert into test values($1,$2)\n");
     116           4 :     exec sql prepare ident_name(int,int) as insert into test values($1,$2);
     117           4 :     printf("execute ident_name(:ivar1,:ivar2)\n");
     118           4 :     exec sql execute ident_name(:ivar1,:ivar2);
     119           4 :     check_result_of_insert();
     120           4 :     exec sql deallocate "ident_name";
     121           4 : 
     122           4 :     exec sql truncate test;
     123           4 :     printf("+++++ Test for PREPARE CString_normal_name(typelist) AS +++++\n");
     124           4 :     printf("prepare \"normal_name\"(int,int) as insert into test values($1,$2)\n");
     125           4 :     exec sql prepare "normal_name"(int,int) as insert into test values($1,$2);
     126           4 :     printf("execute \"normal_name\"(:ivar1,:ivar2)\n");
     127           4 :     exec sql execute "normal_name"(:ivar1,:ivar2);
     128           4 :     check_result_of_insert();
     129           4 :     exec sql deallocate "normal_name";
     130           4 : 
     131           4 :     exec sql truncate test;
     132           4 :     printf("+++++ Test for PREPARE CString_include_ws_name(typelist) AS +++++\n");
     133           4 :     printf("prepare \"include_ _name\"(int,int) as insert into test values($1,$2)\n");
     134           4 :     exec sql prepare "include_ _name"(int,int) as insert into test values($1,$2);
     135           4 :     printf("execute \"include_ _name\"(:ivar1,:ivar2)\n");
     136           4 :     exec sql execute "include_ _name"(:ivar1,:ivar2);
     137           4 :     check_result_of_insert();
     138           4 :     exec sql deallocate "include_ _name";
     139           4 : 
     140           4 :     exec sql truncate test;
     141           4 :     printf("+++++ Test for PREPARE char_variable_normal_name(typelist) AS +++++\n");
     142           4 :     printf("prepare :v_normal_name(int,int) as insert into test values($1,$2)\n");
     143           4 :     exec sql prepare :v_normal_name(int,int) as insert into test values($1,$2);
     144           4 :     printf("execute :v_normal_name(:ivar1,:ivar2)\n");
     145           4 :     exec sql execute :v_normal_name(:ivar1,:ivar2);
     146           4 :     check_result_of_insert();
     147           4 :     exec sql deallocate "normal_name";
     148           4 : 
     149           4 :     exec sql truncate test;
     150           4 :     printf("+++++ Test for PREPARE char_variable_include_ws_name(typelist) AS +++++\n");
     151           4 :     printf("prepare :v_include_ws_name(int,int) as insert into test values($1,$2)\n");
     152           4 :     exec sql prepare :v_include_ws_name(int,int) as insert into test values($1,$2);
     153           4 :     printf("execute :v_include_ws_name(:ivar1,:ivar2)\n");
     154           4 :     exec sql execute :v_include_ws_name(:ivar1,:ivar2);
     155           4 :     check_result_of_insert();
     156           4 :     exec sql deallocate "include_ _name";
     157           4 : 
     158           4 :     exec sql truncate test;
     159           4 :     printf("+++++ Test for EXECUTE :v_normal_name(const,const) +++++\n");
     160           4 :     printf("prepare :v_normal_name from :v_query\n");
     161           4 :     exec sql prepare :v_normal_name from :v_query;
     162           4 :     printf("execute :v_normal_name(1,2)\n");
     163           4 :     exec sql execute :v_normal_name(1,2);
     164           4 :     check_result_of_insert();
     165           4 :     exec sql deallocate "normal_name";
     166           4 : 
     167           4 :     exec sql truncate test;
     168           4 :     printf("+++++ Test for EXECUTE :v_normal_name(expr,expr) +++++\n");
     169           4 :     printf("prepare :v_normal_name from :v_query\n");
     170           4 :     exec sql prepare :v_normal_name from :v_query;
     171           4 :     printf("execute :v_normal_name(0+1,1+1)\n");
     172           4 :     exec sql execute :v_normal_name(0+1,1+1);
     173           4 :     check_result_of_insert();
     174           4 :     exec sql deallocate "normal_name";
     175           4 : 
     176           4 :     exec sql truncate test;
     177           4 :     printf("+++++ Test for combination PREPARE FROM and EXECUTE ident(typelist) +++++\n");
     178           4 :     printf("prepare ident_name from :v_query\n");
     179           4 :     exec sql prepare ident_name from :v_query;
     180           4 :     printf("execute ident_name(:ivar1,:ivar2)\n");
     181           4 :     exec sql execute ident_name(:ivar1,:ivar2);
     182           4 :     check_result_of_insert();
     183           4 :     exec sql deallocate "ident_name";
     184           4 : 
     185           4 :     exec sql truncate test;
     186           4 :     printf("+++++ Test for combination PREPARE FROM and EXECUTE CString_include_ws_name(typelist) +++++\n");
     187           4 :     printf("prepare \"include_ _name\" from :v_query\n");
     188           4 :     exec sql prepare "include_ _name" from :v_query;
     189           4 :     printf("execute \"include_ _name\"(:ivar1,:ivar2)\n");
     190           4 :     exec sql execute "include_ _name"(:ivar1,:ivar2);
     191           4 :     check_result_of_insert();
     192           4 :     exec sql deallocate "include_ _name";
     193           4 : 
     194           4 :     exec sql drop table test;
     195           4 :     exec sql commit work;
     196           4 : 
     197           4 :     return 0;
     198             : }

Generated by: LCOV version 1.13