Software /
code /
prosody
Diff
util/sql.lua @ 5883:39b187e7e892
mod_storage_sql2, util.sql: Move code for setting encoding to util.sql
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 28 Oct 2013 22:07:16 +0100 |
parent | 5776:bd0ff8ae98a8 |
child | 5885:cbc25ae1eea0 |
line wrap: on
line diff
--- a/util/sql.lua Mon Oct 28 21:37:30 2013 +0100 +++ b/util/sql.lua Mon Oct 28 22:07:16 2013 +0100 @@ -276,6 +276,17 @@ end return success; end +function engine:set_encoding() -- to UTF-8 + if self.params.driver == "SQLite3" then return end + local set_names_query = "SET NAMES 'utf8';"; + if self.params.driver == "MySQL" then + set_names_query = set_names_query:gsub(";$", " COLLATE 'utf8_bin';"); + end + local success,err = engine:transaction(function() return engine:execute(set_names_query); end); + if not success then + log("error", "Failed to set database connection encoding to UTF8: %s", err); + end +end local engine_mt = { __index = engine }; local function db2uri(params)