Changeset

8186:becb593ed86d

util.sql: Greedily read all rows so we can close queries early (fixes #391)
author Matthew Wild <mwild1@gmail.com>
date Fri, 04 Aug 2017 18:52:15 +0100
parents 8184:dbcae15b4282
children 8187:4d83876aac3e
files util/sql.lua
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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);