Software / code / prosody
Comparison
plugins/mod_storage_sql.lua @ 8082:8ca11201bfe7
mod_storage_sql: Limit encoding check to current database
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 13 Apr 2017 01:29:35 +0200 |
| parent | 8081:a201f315de55 |
| child | 8083:32898a74b9d9 |
| child | 8138:cb605fb60e32 |
comparison
equal
deleted
inserted
replaced
| 8081:a201f315de55 | 8082:8ca11201bfe7 |
|---|---|
| 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%%' | 487 WHERE "TABLE_NAME" LIKE 'prosody%%' |
| 488 AND "TABLE_SCHEMA" = ? | |
| 488 AND ( "CHARACTER_SET_NAME"!=? OR "COLLATION_NAME"!=?); | 489 AND ( "CHARACTER_SET_NAME"!=? OR "COLLATION_NAME"!=?); |
| 489 ]]; | 490 ]]; |
| 490 -- FIXME Is it ok to ignore the return values from this? | 491 -- FIXME Is it ok to ignore the return values from this? |
| 491 engine:transaction(function() | 492 engine:transaction(function() |
| 492 local result = assert(engine:execute(check_encoding_query, engine.charset, engine.charset.."_bin")); | 493 local result = assert(engine:execute(check_encoding_query, params.database, engine.charset, engine.charset.."_bin")); |
| 493 local n_bad_columns = result:rowcount(); | 494 local n_bad_columns = result:rowcount(); |
| 494 if n_bad_columns > 0 then | 495 if n_bad_columns > 0 then |
| 495 changes = true; | 496 changes = true; |
| 496 if apply_changes then | 497 if apply_changes then |
| 497 module:log("warn", "Found %d columns in prosody table requiring encoding change, updating now...", n_bad_columns); | 498 module:log("warn", "Found %d columns in prosody table requiring encoding change, updating now...", n_bad_columns); |
| 506 module:log("info", "Database encoding upgrade complete!"); | 507 module:log("info", "Database encoding upgrade complete!"); |
| 507 end | 508 end |
| 508 end | 509 end |
| 509 end); | 510 end); |
| 510 success,err = engine:transaction(function() | 511 success,err = engine:transaction(function() |
| 511 return engine:execute(check_encoding_query, engine.charset, engine.charset.."_bin"); | 512 return engine:execute(check_encoding_query, params.database, |
| 513 engine.charset, engine.charset.."_bin"); | |
| 512 end); | 514 end); |
| 513 if not success then | 515 if not success then |
| 514 module:log("error", "Failed to check/upgrade database encoding: %s", err or "unknown error"); | 516 module:log("error", "Failed to check/upgrade database encoding: %s", err or "unknown error"); |
| 515 return false; | 517 return false; |
| 516 end | 518 end |