# HG changeset patch # User Kim Alvefur # Date 1373643870 -7200 # Node ID 253dfea0e3f6cf4983b9220375e0201edc871290 # Parent 8363dda76155f90bfdd7b9e705d30a3f70611630 util.sql: Do lazy fetching of affected/rowcount diff -r 8363dda76155 -r 253dfea0e3f6 util/sql.lua --- a/util/sql.lua Fri Jul 12 17:41:54 2013 +0200 +++ b/util/sql.lua Fri Jul 12 17:44:30 2013 +0200 @@ -177,8 +177,8 @@ end local result_mt = { __index = { - affected = function(self) return self.__affected; end; - rowcount = function(self) return self.__rowcount; end; + affected = function(self) return self.__stmt:affected(); end; + rowcount = function(self) return self.__stmt:rowcount(); end; } }; function engine:execute_query(sql, ...) @@ -200,7 +200,7 @@ prepared[sql] = stmt; end assert(stmt:execute(...)); - return setmetatable({ __affected = stmt:affected(), __rowcount = stmt:rowcount() }, result_mt); + return setmetatable({ __stmt = stmt }, result_mt); end engine.insert = engine.execute_update; engine.select = engine.execute_query;