482 |
482 |
483 -- COMPAT w/pre-0.10: Upgrade table to UTF-8 if not already |
483 -- COMPAT w/pre-0.10: Upgrade table to UTF-8 if not already |
484 local check_encoding_query = [[ |
484 local check_encoding_query = [[ |
485 SELECT "COLUMN_NAME","COLUMN_TYPE","TABLE_NAME" |
485 SELECT "COLUMN_NAME","COLUMN_TYPE","TABLE_NAME" |
486 FROM "information_schema"."columns" |
486 FROM "information_schema"."columns" |
487 WHERE "TABLE_NAME" LIKE 'prosody%%' AND ( "CHARACTER_SET_NAME"!='%s' OR "COLLATION_NAME"!='%s_bin' ); |
487 WHERE "TABLE_NAME" LIKE 'prosody%%' AND ( "CHARACTER_SET_NAME"!=? OR "COLLATION_NAME"!=?); |
488 ]]; |
488 ]]; |
489 check_encoding_query = check_encoding_query:format(engine.charset, engine.charset); |
|
490 -- FIXME Is it ok to ignore the return values from this? |
489 -- FIXME Is it ok to ignore the return values from this? |
491 engine:transaction(function() |
490 engine:transaction(function() |
492 local result = assert(engine:execute(check_encoding_query)); |
491 local result = assert(engine:execute(check_encoding_query, engine.charset, engine.charset.."_bin")); |
493 local n_bad_columns = result:rowcount(); |
492 local n_bad_columns = result:rowcount(); |
494 if n_bad_columns > 0 then |
493 if n_bad_columns > 0 then |
495 changes = true; |
494 changes = true; |
496 if apply_changes then |
495 if apply_changes then |
497 module:log("warn", "Found %d columns in prosody table requiring encoding change, updating now...", n_bad_columns); |
496 module:log("warn", "Found %d columns in prosody table requiring encoding change, updating now...", n_bad_columns); |
505 end |
504 end |
506 module:log("info", "Database encoding upgrade complete!"); |
505 module:log("info", "Database encoding upgrade complete!"); |
507 end |
506 end |
508 end |
507 end |
509 end); |
508 end); |
510 success,err = engine:transaction(function() return engine:execute(check_encoding_query); end); |
509 success,err = engine:transaction(function() return engine:execute(check_encoding_query, engine.charset, engine.charset.."_bin"); end); |
511 if not success then |
510 if not success then |
512 module:log("error", "Failed to check/upgrade database encoding: %s", err or "unknown error"); |
511 module:log("error", "Failed to check/upgrade database encoding: %s", err or "unknown error"); |
513 return false; |
512 return false; |
514 end |
513 end |
515 end |
514 end |