Comparison

plugins/mod_storage_sql2.lua @ 5881:12d12bda4b8c

mod_storage_sql2: Split up setting of encoding and table upgrade code
author Kim Alvefur <zash@zash.se>
date Mon, 28 Oct 2013 21:34:55 +0100
parent 5848:06156bfd4eaf
child 5882:fbba2997aabb
comparison
equal deleted inserted replaced
5874:3321a4b3e6c4 5881:12d12bda4b8c
106 set_names_query = set_names_query:gsub(";$", " COLLATE 'utf8_bin';"); 106 set_names_query = set_names_query:gsub(";$", " COLLATE 'utf8_bin';");
107 end 107 end
108 local success,err = engine:transaction(function() return engine:execute(set_names_query); end); 108 local success,err = engine:transaction(function() return engine:execute(set_names_query); end);
109 if not success then 109 if not success then
110 module:log("error", "Failed to set database connection encoding to UTF8: %s", err); 110 module:log("error", "Failed to set database connection encoding to UTF8: %s", err);
111 return; 111 end
112 end 112 end
113 local function upgrade_table()
113 if params.driver == "MySQL" then 114 if params.driver == "MySQL" then
114 -- COMPAT w/pre-0.9: Upgrade tables to UTF-8 if not already 115 -- COMPAT w/pre-0.9: Upgrade tables to UTF-8 if not already
115 local check_encoding_query = "SELECT `COLUMN_NAME`,`COLUMN_TYPE` FROM `information_schema`.`columns` WHERE `TABLE_NAME`='prosody' AND ( `CHARACTER_SET_NAME`!='utf8' OR `COLLATION_NAME`!='utf8_bin' );"; 116 local check_encoding_query = "SELECT `COLUMN_NAME`,`COLUMN_TYPE` FROM `information_schema`.`columns` WHERE `TABLE_NAME`='prosody' AND ( `CHARACTER_SET_NAME`!='utf8' OR `COLLATION_NAME`!='utf8_bin' );";
116 local success,err = engine:transaction(function() 117 local success,err = engine:transaction(function()
117 local result = engine:execute(check_encoding_query); 118 local result = engine:execute(check_encoding_query);
147 --local dburi = db2uri(params); 148 --local dburi = db2uri(params);
148 engine = mod_sql:create_engine(params); 149 engine = mod_sql:create_engine(params);
149 150
150 -- Encoding mess 151 -- Encoding mess
151 set_encoding(); 152 set_encoding();
153 upgrade_table();
152 154
153 -- Automatically create table, ignore failure (table probably already exists) 155 -- Automatically create table, ignore failure (table probably already exists)
154 create_table(); 156 create_table();
155 end 157 end
156 158