# HG changeset patch # User Matthew Wild # Date 1501869135 -3600 # Node ID becb593ed86d39e2aba1efe21d2bee0603e1b480 # Parent dbcae15b4282c23163b9a1e6b0c760f3d41d94b5 util.sql: Greedily read all rows so we can close queries early (fixes #391) diff -r dbcae15b4282 -r becb593ed86d util/sql.lua --- a/util/sql.lua Fri Jul 28 23:45:05 2017 +0100 +++ b/util/sql.lua Fri Aug 04 18:52:15 2017 +0100 @@ -175,7 +175,11 @@ sql = self:prepquery(sql); local stmt = assert(self.conn:prepare(sql)); 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 function engine:execute_update(sql, ...) sql = self:prepquery(sql);