aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2015-07-08 15:25:42 +0100
committerMatthew Wild <mwild1@gmail.com>2015-07-08 15:25:42 +0100
commit376dd433962a1a897a239d06dbc91d3e03290fe3 (patch)
tree861e27cbc56dbdb20c61ecbbc32d148bfb400ca6
parentc23293f38250ac5f85a813452a6d4973ea94b5fe (diff)
downloadprosody-376dd433962a1a897a239d06dbc91d3e03290fe3.tar.gz
prosody-376dd433962a1a897a239d06dbc91d3e03290fe3.zip
util.sql: Add safety check to ensure our chosen connection charset is actually being used (MySQL)
-rw-r--r--util/sql.lua12
1 files changed, 12 insertions, 0 deletions
diff --git a/util/sql.lua b/util/sql.lua
index 693b67d9..f934bbdf 100644
--- a/util/sql.lua
+++ b/util/sql.lua
@@ -286,6 +286,18 @@ function engine:set_encoding() -- to UTF-8
return ok, err;
end
+ if driver == "MySQL" then
+ local ok, actual_charset = self:transaction(function ()
+ return self:select"SHOW SESSION VARIABLES LIKE 'character_set_client'";
+ end);
+ for row in actual_charset do
+ if row[2] ~= charset then
+ log("error", "MySQL %s is actually %q (expected %q)", row[1], row[2], charset);
+ return false, "Failed to set connection encoding";
+ end
+ end
+ end
+
return true;
end
local engine_mt = { __index = engine };