util.sql: Produce more SQL-standard-like debug messages
authorKim Alvefur <zash@zash.se>
Thu, 13 Apr 2017 22:37:35 +0200
changeset 8087 655837e9eeeb
parent 8085 8ca11201bfe7
child 8088 7a13fa890472
child 8089 4d363834f36d
util.sql: Produce more SQL-standard-like debug messages
util/sql.lua
--- a/util/sql.lua	Thu Apr 13 01:29:35 2017 +0200
+++ b/util/sql.lua	Thu Apr 13 22:37:35 2017 +0200
@@ -161,7 +161,14 @@
 local function debugquery(where, sql, ...)
 	local i = 0; local a = {...}
 	sql = sql:gsub("\n?\t+", " ");
-	log("debug", "[%s] %s", where, sql:gsub("%?", function () i = i + 1; local v = a[i]; if type(v) == "string" then v = ("%q"):format(v); end return tostring(v); end));
+	log("debug", "[%s] %s", where, sql:gsub("%?", function ()
+		i = i + 1;
+		local v = a[i];
+		if type(v) == "string" then
+			v = ("'%s'"):format(v:gsub("'", "''"));
+		end
+		return tostring(v);
+	end));
 end
 
 function engine:execute_query(sql, ...)