From 3604a84b9eca4e5790310552a6c78692a892ec1f Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Wed, 12 Apr 2017 17:26:44 +0200
Subject: util.sql: Apply quote transform in engine:execute so it is applied to
 eg encoding checks in mod_storage_sql (thanks Martin)

---
 util/sql.lua | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

(limited to 'util')

diff --git a/util/sql.lua b/util/sql.lua
index a859ddc9..c7a79278 100644
--- a/util/sql.lua
+++ b/util/sql.lua
@@ -139,6 +139,7 @@ function engine:execute(sql, ...)
 	if not success then return success, err; end
 	local prepared = self.prepared;
 
+	sql = self:prepquery(sql);
 	local stmt = prepared[sql];
 	if not stmt then
 		local err;
@@ -254,7 +255,6 @@ function engine:_create_index(index)
 	if index.unique then
 		sql = sql:gsub("^CREATE", "CREATE UNIQUE");
 	end
-	sql = self:prepquery(sql);
 	if self._debug then
 		debugquery("create", sql);
 	end
@@ -286,7 +286,6 @@ function engine:_create_table(table)
 	if self.params.driver == "MySQL" then
 		sql = sql:gsub(";$", (" CHARACTER SET '%s' COLLATE '%s_bin';"):format(self.charset, self.charset));
 	end
-	sql = self:prepquery(sql);
 	if self._debug then
 		debugquery("create", sql);
 	end
-- 
cgit v1.2.3


From 2b914fee7d809f0666ca96db8ee49dd4f64db66c Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Wed, 12 Apr 2017 18:57:40 +0200
Subject: util.sql: Strip indentation from queries for debug logging

---
 util/sql.lua | 1 +
 1 file changed, 1 insertion(+)

(limited to 'util')

diff --git a/util/sql.lua b/util/sql.lua
index c7a79278..f7c68ed3 100644
--- a/util/sql.lua
+++ b/util/sql.lua
@@ -160,6 +160,7 @@ local result_mt = { __index = {
 
 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));
 end
 
-- 
cgit v1.2.3