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