Comparison

util/sql.lua @ 6766:b38db4b634d3

util.sql: Add safety check to ensure our chosen connection charset is actually being used (MySQL)
author Matthew Wild <mwild1@gmail.com>
date Wed, 08 Jul 2015 15:25:42 +0100
parent 6765:0cbb09afa5c3
child 6771:60957dd5b41b
comparison
equal deleted inserted replaced
6765:0cbb09afa5c3 6766:b38db4b634d3
284 local ok, err = self:transaction(function() return self:execute(set_names_query:format(charset)); end); 284 local ok, err = self:transaction(function() return self:execute(set_names_query:format(charset)); end);
285 if not ok then 285 if not ok then
286 return ok, err; 286 return ok, err;
287 end 287 end
288 288
289 if driver == "MySQL" then
290 local ok, actual_charset = self:transaction(function ()
291 return self:select"SHOW SESSION VARIABLES LIKE 'character_set_client'";
292 end);
293 for row in actual_charset do
294 if row[2] ~= charset then
295 log("error", "MySQL %s is actually %q (expected %q)", row[1], row[2], charset);
296 return false, "Failed to set connection encoding";
297 end
298 end
299 end
300
289 return true; 301 return true;
290 end 302 end
291 local engine_mt = { __index = engine }; 303 local engine_mt = { __index = engine };
292 304
293 function db2uri(params) 305 function db2uri(params)