util.sql: Add safety check to ensure our chosen connection charset is actually being...
authorMatthew Wild <mwild1@gmail.com>
Wed, 8 Jul 2015 14:25:42 +0000 (15:25 +0100)
committerMatthew Wild <mwild1@gmail.com>
Wed, 8 Jul 2015 14:25:42 +0000 (15:25 +0100)
util/sql.lua

index 693b67d955be08319e879e126cdf5f3db201a62d..f934bbdf91b83e763b20e1a64ed57f3ea4cfca19 100644 (file)
@@ -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 };