| 3572 | // Check for corruption before performing the DB charset conversion |
| 3573 | // (Some system configurations have been converting the UTF8 data Myth |
| 3574 | // writes to latin1) |
| 3575 | MSqlQuery query(MSqlQuery::InitCon()); |
| 3576 | int tableIndex = 0; |
| 3577 | QString tables[][2] = { |
| 3578 | { "people", "name" }, |
| 3579 | { "oldprogram", "oldtitle" }, |
| 3580 | { "", "" } }; // This blank entry must exist, do not remove. |
| 3581 | QString table = tables[tableIndex][0]; |
| 3582 | QString column = tables[tableIndex][1]; |
| 3583 | |
| 3584 | while (table != "") |
| 3585 | { |
| 3586 | bool ok = true; |
| 3587 | QString thequery = QString("CREATE TEMPORARY TABLE temp_%1 " |
| 3588 | " SELECT * FROM %2;") |
| 3589 | .arg(table).arg(table); |
| 3590 | ok &= query.exec(thequery); |
| 3591 | if (ok) |
| 3592 | { |
| 3593 | thequery = QString("ALTER TABLE temp_%1 " |
| 3594 | " MODIFY %2 varbinary(128) " |
| 3595 | " NOT NULL default '';") |
| 3596 | .arg(table).arg(column); |
| 3597 | ok &= query.exec(thequery); |
| 3598 | } |
| 3599 | if (ok) |
| 3600 | { |
| 3601 | thequery = QString("ALTER TABLE temp_%1 " |
| 3602 | " MODIFY %2 char(128) CHARACTER SET utf8 " |
| 3603 | " COLLATE utf8_bin " |
| 3604 | " NOT NULL default '';") |
| 3605 | .arg(table).arg(column); |
| 3606 | ok &= query.exec(thequery); |
| 3607 | } |
| 3608 | if (!ok) |
| 3609 | { |
| 3610 | MythDB::DBError(QString("Unable to perform test for database " |
| 3611 | "corruption before character set conversion."), |
| 3612 | thequery); |
| 3613 | return false; |
| 3614 | } |
| 3615 | // If the conversion to utf8 resulted in warnings, the data in the |
| 3616 | // database is not in utf8 format/is corrupt |
| 3617 | thequery = "SHOW COUNT(*) WARNINGS;"; |
| 3618 | if (query.exec(thequery) && query.isActive() && |
| 3619 | query.size() > 0 && query.next()) |
| 3620 | { |
| 3621 | int warnings = query.value(0).toInt(); |
| 3622 | if (warnings) |
| 3623 | { |
| 3624 | QString msg = QString("Database corruption detected. " |
| 3625 | "Unable to proceed with database " |
| 3626 | "upgrade. (Table: %1, Warnings: %2)") |
| 3627 | .arg(table).arg(warnings); |
| 3628 | VERBOSE(VB_IMPORTANT, msg); |
| 3629 | VERBOSE(VB_IMPORTANT, "Your database must be fixed before " |
| 3630 | "you can upgrade beyond 0.21-fixes. Please see" |
| 3631 | "http://www.mythtv.org/wiki/index.php/" |
| 3632 | "Fixing_Corrupt_Database_Encoding for information " |
| 3633 | "on fixing your database."); |
| 3634 | return false; |
| 3635 | } |
| 3636 | } |
| 3637 | else |
| 3638 | { |
| 3639 | MythDB::DBError(QString("Error getting database warnings for " |
| 3640 | "database corruption test."), |
| 3641 | thequery); |
| 3642 | return false; |
| 3643 | } |
| 3644 | thequery = QString("DROP TEMPORARY TABLE temp_%1;").arg(table); |
| 3645 | if (!query.exec(thequery)) |
| 3646 | MythDB::DBError(QString("Error dropping temporary table %1.") |
| 3647 | .arg(table), |
| 3648 | thequery); |
| 3649 | |
| 3650 | tableIndex++; |
| 3651 | table = tables[tableIndex][0]; |
| 3652 | column = tables[tableIndex][1]; |
| 3653 | } |
| 3654 | |
| 3655 | |
| 3656 | // Perform the actual upgrade |