aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2013-10-28 22:07:16 +0100
committerKim Alvefur <zash@zash.se>2013-10-28 22:07:16 +0100
commite9935707592087e51ec0e6e63e3fd389407ebe9a (patch)
tree4648b821daf0aa3a8b8edacae44339d3fdd6c534
parentd011ca8a325fc9bda520898a58a0c255d8c52968 (diff)
downloadprosody-e9935707592087e51ec0e6e63e3fd389407ebe9a.tar.gz
prosody-e9935707592087e51ec0e6e63e3fd389407ebe9a.zip
mod_storage_sql2, util.sql: Move code for setting encoding to util.sql
-rw-r--r--plugins/mod_storage_sql2.lua14
-rw-r--r--util/sql.lua11
2 files changed, 13 insertions, 12 deletions
diff --git a/plugins/mod_storage_sql2.lua b/plugins/mod_storage_sql2.lua
index 90e9a2f6..0e6aca3a 100644
--- a/plugins/mod_storage_sql2.lua
+++ b/plugins/mod_storage_sql2.lua
@@ -82,17 +82,7 @@ local function create_table()
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 @@ do -- process options to get a db connection
--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();
diff --git a/util/sql.lua b/util/sql.lua
index b8c16e27..972940f7 100644
--- a/util/sql.lua
+++ b/util/sql.lua
@@ -276,6 +276,17 @@ function engine:_create_table(table)
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)