--
-- ### check of user function for usage leaks  
-- fix with version 2.48.41
-- 

drop if exists counter logid;
create counter logid;

drop if exists table acc_log;
create table acc_log ( logid int, rxid int, logts datetime, logtype string(20), logmsg string(100));


drop if exists procedure addLog;
@
create procedure addLog(rxid in int,
    logtype in string(10),
    logmsg in string(3000)) return int
begin
   var logid int;
   :logid = nextcount(logid);
   insert into acc_log ( logid, rxid, logts, logtype, logmsg )
    values (:logid, :rxid, sysdate, :logtype, :logmsg );
   return :logid;
end;
@


drop if exists procedure doRollback;
@
create procedure doRollback(
    rxid in int ) return int
begin

       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       addLog(:rxid, 'INFO', 'Rolling back ' | :rxid);
       return 1;
end;
@

-- this proc call causes a usage leak
:a = call addLog(1, 'INFO', 'Rolling back ');

:a = call doRollback(42);
:a = call doRollback(42);
:a = call doRollback(42);
:a = call doRollback(42);

print :a;
