Comparison

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
comparison
equal deleted inserted replaced
5882:fbba2997aabb 5883:39b187e7e892
274 self:_create_index(v); 274 self:_create_index(v);
275 end 275 end
276 end 276 end
277 return success; 277 return success;
278 end 278 end
279 function engine:set_encoding() -- to UTF-8
280 if self.params.driver == "SQLite3" then return end
281 local set_names_query = "SET NAMES 'utf8';";
282 if self.params.driver == "MySQL" then
283 set_names_query = set_names_query:gsub(";$", " COLLATE 'utf8_bin';");
284 end
285 local success,err = engine:transaction(function() return engine:execute(set_names_query); end);
286 if not success then
287 log("error", "Failed to set database connection encoding to UTF8: %s", err);
288 end
289 end
279 local engine_mt = { __index = engine }; 290 local engine_mt = { __index = engine };
280 291
281 local function db2uri(params) 292 local function db2uri(params)
282 return build_url{ 293 return build_url{
283 scheme = params.driver, 294 scheme = params.driver,