Comparison

util/sql.lua @ 8380:a597ff326758

util.sql: Discard useless substitution count from string.gsub in SQL debug logs
author Kim Alvefur <zash@zash.se>
date Wed, 08 Nov 2017 10:45:58 +0100
parent 8378:6a098961bc00
child 8382:e5d00bf4a4d5
comparison
equal deleted inserted replaced
8379:2a0915aa6131 8380:a597ff326758
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 sql = sql:gsub("\n?\t+", " ");
164 log("debug", "[%s] %s", where, sql:gsub("%?", function () 164 log("debug", "[%s] %s", where, (sql:gsub("%?", function ()
165 i = i + 1; 165 i = i + 1;
166 local v = a[i]; 166 local v = a[i];
167 if type(v) == "string" then 167 if type(v) == "string" then
168 v = ("'%s'"):format(v:gsub("'", "''")); 168 v = ("'%s'"):format(v:gsub("'", "''"));
169 end 169 end
170 return tostring(v); 170 return tostring(v);
171 end)); 171 end)));
172 end 172 end
173 173
174 function engine:execute_query(sql, ...) 174 function engine:execute_query(sql, ...)
175 sql = self:prepquery(sql); 175 sql = self:prepquery(sql);
176 local stmt = assert(self.conn:prepare(sql)); 176 local stmt = assert(self.conn:prepare(sql));