Comparison

util/sql.lua @ 8077:29b3957db212

util.sql: Strip indentation from queries for debug logging
author Kim Alvefur <zash@zash.se>
date Wed, 12 Apr 2017 18:57:40 +0200
parent 8076:6e0defa19ab9
child 8084:655837e9eeeb
comparison
equal deleted inserted replaced
8076:6e0defa19ab9 8077:29b3957db212
158 rowcount = function(self) return self.__stmt:rowcount(); end; 158 rowcount = function(self) return self.__stmt:rowcount(); end;
159 } }; 159 } };
160 160
161 local function debugquery(where, sql, ...) 161 local function debugquery(where, sql, ...)
162 local i = 0; local a = {...} 162 local i = 0; local a = {...}
163 sql = sql:gsub("\n?\t+", " ");
163 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)); 164 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));
164 end 165 end
165 166
166 function engine:execute_query(sql, ...) 167 function engine:execute_query(sql, ...)
167 sql = self:prepquery(sql); 168 sql = self:prepquery(sql);