util.sql: Greedily read all rows so we can close queries early (fixes #391)

This commit is contained in:
Matthew Wild 2017-08-04 18:52:15 +01:00
parent 15ee257b35
commit c5af3aee3e

View file

@ -175,7 +175,11 @@ function engine:execute_query(sql, ...)
sql = self:prepquery(sql); sql = self:prepquery(sql);
local stmt = assert(self.conn:prepare(sql)); local stmt = assert(self.conn:prepare(sql));
assert(stmt:execute(...)); assert(stmt:execute(...));
return stmt:rows(); local result = {};
for row in stmt:rows() do result[#result + 1] = row; end
stmt:close();
local i = 0;
return function() i=i+1; return result[i]; end;
end end
function engine:execute_update(sql, ...) function engine:execute_update(sql, ...)
sql = self:prepquery(sql); sql = self:prepquery(sql);