Software /
code /
prosody
Comparison
util/sql.lua @ 5888:f3e408ae59a6
util.sql: Find out if MySQL supports utf8mb4 and use that
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 29 Oct 2013 11:42:55 +0100 |
parent | 5887:1f860279b2f8 |
child | 5889:ea6a3adb6a69 |
comparison
equal
deleted
inserted
replaced
5887:1f860279b2f8 | 5888:f3e408ae59a6 |
---|---|
289 end | 289 end |
290 return success; | 290 return success; |
291 end | 291 end |
292 function engine:set_encoding() -- to UTF-8 | 292 function engine:set_encoding() -- to UTF-8 |
293 if self.params.driver == "SQLite3" then return end | 293 if self.params.driver == "SQLite3" then return end |
294 local set_names_query = "SET NAMES 'utf8';"; | 294 local driver = self.params.driver; |
295 if self.params.driver == "MySQL" then | 295 local set_names_query = "SET NAMES '%s';" |
296 local charset = "utf8"; | |
297 if driver == "MySQL" then | |
296 set_names_query = set_names_query:gsub(";$", " COLLATE 'utf8_bin';"); | 298 set_names_query = set_names_query:gsub(";$", " COLLATE 'utf8_bin';"); |
297 end | 299 local ok, charsets = self:transaction(function() |
298 local success,err = engine:transaction(function() return engine:execute(set_names_query); end); | 300 return self:select"SELECT `CHARACTER_SET_NAME` FROM `CHARACTER_SETS` WHERE `CHARACTER_SET_NAME` LIKE 'utf8%' ORDER BY MAXLEN DESC LIMIT 1;"; |
299 if not success then | 301 end); |
300 log("error", "Failed to set database connection encoding to UTF8: %s", err); | 302 local row = ok and charsets(); |
301 end | 303 charset = row and row[1] or charset; |
304 end | |
305 self.charset = charset; | |
306 return self:transaction(function() return engine:execute(set_names_query:format(charset)); end); | |
302 end | 307 end |
303 local engine_mt = { __index = engine }; | 308 local engine_mt = { __index = engine }; |
304 | 309 |
305 local function db2uri(params) | 310 local function db2uri(params) |
306 return build_url{ | 311 return build_url{ |