--
-- ### Check parent join buf reset 
--
-- and basic table creation / retrieval
--

drop if exists table t1;
create table t1 ( a int, b string(30));

drop if exists table t2;
create table t2 ( c int, d string(30));

drop if exists table t3;
create table t3 ( e int, f string(30));

insert into t1 values ( 1 , 'alpha');
insert into t1 values ( 2 , 'beta');
insert into t1 values ( 3 , 'gamma');

insert into t2 values ( 1 , 'alpha');
insert into t2 values ( 2 , 'beta');
insert into t2 values ( 3 , 'gamma');

insert into t3 values ( 1 , 'alpha');
insert into t3 values ( 2 , 'beta');
insert into t3 values ( 3 , 'gamma');

drop if exists procedure checkQueryInProc;

@
create procedure checkQueryInProc(x in string(30)) return int
begin
   var a int;
   :a = ( select a from t1 where a = ( select c from t2 where c = ( select e from t3 where f = :x)));
   return :a;
end;
@

:i = call checkQueryInProc('alpha');
print :i;
:i = call checkQueryInProc('beta');
print :i;
:i = call checkQueryInProc('gamma');
print :i;
