From 3ae5b45b187738b67146230666fc4d2f9fd5458d Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Fri, 28 Nov 2014 15:23:33 +0000 Subject: Fix db bug when execute(sql) returns a number instead of a cursor --- db.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/db.lua b/db.lua index 626b268..0b6da43 100644 --- a/db.lua +++ b/db.lua @@ -96,7 +96,10 @@ export.getselectresponse = function(dbobject, sql, transaction) if transaction then assert(dbobject.con:execute("SAVEPOINT before_select")) end local res, err = pcall(function() local cur = assert (dbobject.con:execute(sql)) - local row = cur:fetch ({}, "a") + local row + if type(cur) == "userdata" then + row = cur:fetch ({}, "a") + end while row do local tmp = {} for name,val in pairs(row) do @@ -105,7 +108,9 @@ export.getselectresponse = function(dbobject, sql, transaction) retval[#retval + 1] = tmp row = cur:fetch (row, "a") end - cur:close() + if type(cur) == "userdata" then + cur:close() + end end) if not res and err then -- Catch the error to see if it's caused by lack of table -- cgit v1.2.3