Diff

util/sql.lua @ 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
parent 8084:655837e9eeeb
child 8288:e9ac2d93de18
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);