Comparison

plugins/mod_storage_sql2.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 5882:fbba2997aabb
child 5884:9cb81a17ae23
comparison
equal deleted inserted replaced
5882:fbba2997aabb 5883:39b187e7e892
80 }; 80 };
81 engine:transaction(function() 81 engine:transaction(function()
82 ProsodyArchiveTable:create(engine); 82 ProsodyArchiveTable:create(engine);
83 end); 83 end);
84 end 84 end
85 local function set_encoding() 85
86 if params.driver == "SQLite3" then return end
87 local set_names_query = "SET NAMES 'utf8';";
88 if params.driver == "MySQL" then
89 set_names_query = set_names_query:gsub(";$", " COLLATE 'utf8_bin';");
90 end
91 local success,err = engine:transaction(function() return engine:execute(set_names_query); end);
92 if not success then
93 module:log("error", "Failed to set database connection encoding to UTF8: %s", err);
94 end
95 end
96 local function upgrade_table() 86 local function upgrade_table()
97 if params.driver == "MySQL" then 87 if params.driver == "MySQL" then
98 local success,err = engine:transaction(function() 88 local success,err = engine:transaction(function()
99 local result = engine:execute("SHOW COLUMNS FROM prosody WHERE Field='value' and Type='text'"); 89 local result = engine:execute("SHOW COLUMNS FROM prosody WHERE Field='value' and Type='text'");
100 if result:rowcount() > 0 then 90 if result:rowcount() > 0 then
144 assert(params.driver and params.database, "Both the SQL driver and the database need to be specified"); 134 assert(params.driver and params.database, "Both the SQL driver and the database need to be specified");
145 135
146 --local dburi = db2uri(params); 136 --local dburi = db2uri(params);
147 engine = mod_sql:create_engine(params); 137 engine = mod_sql:create_engine(params);
148 138
149 set_encoding(); 139 engine:set_encoding();
150 140
151 -- Automatically create table, ignore failure (table probably already exists) 141 -- Automatically create table, ignore failure (table probably already exists)
152 create_table(); 142 create_table();
153 -- Encoding mess 143 -- Encoding mess
154 upgrade_table(); 144 upgrade_table();