aboutsummaryrefslogtreecommitdiffstats
path: root/util/sql.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2017-08-04 18:52:15 +0100
committerMatthew Wild <mwild1@gmail.com>2017-08-04 18:52:15 +0100
commitc5af3aee3e651187a3a582045dbe269e1b61fe4d (patch)
tree023d692fd91552c893cc224b72d984e32a49ae54 /util/sql.lua
parent15ee257b357d532f7c8dc1de83b0379b57203268 (diff)
downloadprosody-c5af3aee3e651187a3a582045dbe269e1b61fe4d.tar.gz
prosody-c5af3aee3e651187a3a582045dbe269e1b61fe4d.zip
util.sql: Greedily read all rows so we can close queries early (fixes #391)
Diffstat (limited to 'util/sql.lua')
-rw-r--r--util/sql.lua6
1 files changed, 5 insertions, 1 deletions
diff --git a/util/sql.lua b/util/sql.lua
index 15749911..61d6af41 100644
--- a/util/sql.lua
+++ b/util/sql.lua
@@ -175,7 +175,11 @@ function engine:execute_query(sql, ...)
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);