Comparison

util/sql.lua @ 9616:61376a3c0c1d 0.11

util.sql: Switch from hacky multi-arg xpcall implementation to util.xpcall
author Kim Alvefur <zash@zash.se>
date Sun, 11 Nov 2018 02:26:40 +0100
parent 8555:4f0f5b49bb03
child 10038:7dd0dddd8e02
comparison
equal deleted inserted replaced
9613:4d7b925652d9 9616:61376a3c0c1d
1 1
2 local setmetatable, getmetatable = setmetatable, getmetatable; 2 local setmetatable, getmetatable = setmetatable, getmetatable;
3 local ipairs, unpack, select = ipairs, table.unpack or unpack, select; --luacheck: ignore 113 143 3 local ipairs = ipairs;
4 local tostring = tostring; 4 local tostring = tostring;
5 local type = type; 5 local type = type;
6 local assert, pcall, xpcall, debug_traceback = assert, pcall, xpcall, debug.traceback; 6 local assert, pcall, debug_traceback = assert, pcall, debug.traceback;
7 local xpcall = require "util.xpcall".xpcall;
7 local t_concat = table.concat; 8 local t_concat = table.concat;
8 local log = require "util.logger".init("sql"); 9 local log = require "util.logger".init("sql");
9 10
10 local DBI = require "DBI"; 11 local DBI = require "DBI";
11 -- This loads all available drivers while globals are unlocked 12 -- This loads all available drivers while globals are unlocked
198 if not self.conn then 199 if not self.conn then
199 local ok, err = self:connect(); 200 local ok, err = self:connect();
200 if not ok then return ok, err; end 201 if not ok then return ok, err; end
201 end 202 end
202 --assert(not self.__transaction, "Recursive transactions not allowed"); 203 --assert(not self.__transaction, "Recursive transactions not allowed");
203 local args, n_args = {...}, select("#", ...);
204 local function f() return func(unpack(args, 1, n_args)); end
205 log("debug", "SQL transaction begin [%s]", tostring(func)); 204 log("debug", "SQL transaction begin [%s]", tostring(func));
206 self.__transaction = true; 205 self.__transaction = true;
207 local success, a, b, c = xpcall(f, handleerr); 206 local success, a, b, c = xpcall(func, handleerr, ...);
208 self.__transaction = nil; 207 self.__transaction = nil;
209 if success then 208 if success then
210 log("debug", "SQL transaction success [%s]", tostring(func)); 209 log("debug", "SQL transaction success [%s]", tostring(func));
211 local ok, err = self.conn:commit(); 210 local ok, err = self.conn:commit();
212 -- LuaDBI doesn't actually return an error message here, just a boolean 211 -- LuaDBI doesn't actually return an error message here, just a boolean