-- Untested code
-- You'll have to declare next, unpack and table as locals to
-- provide access to them
function select (self, columns, tabname, cond, extra, mode)
local stmt = sql.select (columns, tabname, cond, extra)
local cur = assertexec (self, stmt)
return function ()
-- This table must be created inside this function or it could
-- make `selectall' to return the same row every time.
local t
if mode then t = {} end
--return cur:fetch (t, mode)
local results = { cur:fetch (t, mode) }
if next(results) == nil then -- no more rows
cur:close()
return nil
else
return unpack (results, 1, table.maxn(results))
end
end
end
-- Untested code
function select (self, columns, tabname, cond, extra, mode)
local stmt = sql.select (columns, tabname, cond, extra)
local cur = assertexec (self, stmt)
return function ()
-- This table must be created inside this function or it could
-- make `selectall' to return the same row every time.
local t
if mode then t = {} end
return cur:fetch (t, mode)
end, cur
end
...
local iter, cur = db:select ("*", "table", nil, nil, "a")
for row in iter do
...
end
cur:close()
Regards,
Tomás