Software /
code /
prosody
Changeset
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 |
parents | 5882:fbba2997aabb |
children | 5884:9cb81a17ae23 |
files | plugins/mod_storage_sql2.lua util/sql.lua |
diffstat | 2 files changed, 13 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_storage_sql2.lua Mon Oct 28 21:37:30 2013 +0100 +++ b/plugins/mod_storage_sql2.lua Mon Oct 28 22:07:16 2013 +0100 @@ -82,17 +82,7 @@ ProsodyArchiveTable:create(engine); end); end -local function set_encoding() - if params.driver == "SQLite3" then return end - local set_names_query = "SET NAMES 'utf8';"; - if 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 - module:log("error", "Failed to set database connection encoding to UTF8: %s", err); - end -end + local function upgrade_table() if params.driver == "MySQL" then local success,err = engine:transaction(function() @@ -146,7 +136,7 @@ --local dburi = db2uri(params); engine = mod_sql:create_engine(params); - set_encoding(); + engine:set_encoding(); -- Automatically create table, ignore failure (table probably already exists) create_table();
--- 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)