plugins/mod_debug_sql.lua
author Kim Alvefur <zash@zash.se>
Wed, 19 Apr 2023 11:32:53 +0200
branch0.12
changeset 13082 6da83deb8d7f
parent 8394 5edb0d01a94f
permissions -rw-r--r--
util.error: Fix error on conversion of invalid error stanza, fix #1805 Error stanzas should have an <error> element, but if you pass a stanza without one to util.error.from_stanza() it triggers an attempt to index a nil value, which this patch avoids. In the conditional, it should be safe to assume error_tag is non-nil since condition can't have those values then.

-- Enables SQL query logging
--
-- luacheck: ignore 213/uri

module:set_global();

local engines = module:shared("/*/sql/connections");

for uri, engine in pairs(engines) do
	engine:debug(true);
end

setmetatable(engines, {
	__newindex = function (t, uri, engine)
		engine:debug(true);
		rawset(t, uri, engine);
	end
});

function module.unload()
	setmetatable(engines, nil);
	for uri, engine in pairs(engines) do
		engine:debug(false);
	end
end