Software /
code /
prosody
Changeset
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 |
parents | 6765:0cbb09afa5c3 |
children | 6767:d01c29b62b16 6771:60957dd5b41b |
files | util/sql.lua |
diffstat | 1 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/util/sql.lua Wed Jul 08 15:16:17 2015 +0100 +++ b/util/sql.lua Wed Jul 08 15:25:42 2015 +0100 @@ -286,6 +286,18 @@ 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 };