diff options
author | Matthew Wild <mwild1@gmail.com> | 2017-08-04 18:52:15 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2017-08-04 18:52:15 +0100 |
commit | 6bb4201fe2c08ce36e23459b5f0f93e515587fe5 (patch) | |
tree | 023d692fd91552c893cc224b72d984e32a49ae54 | |
parent | 8049a9c15fdbf78f0284240ef532e90228e6d4ad (diff) | |
download | prosody-6bb4201fe2c08ce36e23459b5f0f93e515587fe5.tar.gz prosody-6bb4201fe2c08ce36e23459b5f0f93e515587fe5.zip |
util.sql: Greedily read all rows so we can close queries early (fixes #391)
-rw-r--r-- | util/sql.lua | 6 |
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); |