What's the proper pattern to close all open cursors in a lua script before closing the db connection? I have a helper function rows() that is called in multiple places which creates cursors, on the function end() I want to be able to close all that have been created.
function rows (sql_statement)
local cursor = assert (con:execute (sql_statement));
local closed = false;
return function ()
if (closed) then return nil end;
local row = {};
result = cursor:fetch(row);
if (result == nil) then
cursor:close();
closed = true;
return nil;
end;
return row;
end
end
function end()
-- this con:close() call fails because of open cursors
con:close();
env:close();
end