Comparison

util/sql.lua @ 8084:655837e9eeeb

util.sql: Produce more SQL-standard-like debug messages
author Kim Alvefur <zash@zash.se>
date Thu, 13 Apr 2017 22:37:35 +0200
parent 8077:29b3957db212
child 8186:becb593ed86d
comparison
equal deleted inserted replaced
8082:8ca11201bfe7 8084:655837e9eeeb
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 () 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 ()
165 i = i + 1;
166 local v = a[i];
167 if type(v) == "string" then
168 v = ("'%s'"):format(v:gsub("'", "''"));
169 end
170 return tostring(v);
171 end));
165 end 172 end
166 173
167 function engine:execute_query(sql, ...) 174 function engine:execute_query(sql, ...)
168 sql = self:prepquery(sql); 175 sql = self:prepquery(sql);
169 local stmt = assert(self.conn:prepare(sql)); 176 local stmt = assert(self.conn:prepare(sql));