From 2ffdf2626b2f074baa5d8eaeed97a9b8cfcc38a2 Mon Sep 17 00:00:00 2001
From: Lawrence Rust <lvr@softsystem.co.uk>
Date: Thu, 11 Aug 2011 10:49:58 +0200
Subject: [PATCH] Fix upgrade from an empty database
mythtv-setup fails when starting with an empty database, failing during
the wizard upgrade step from the intiak database schema 1226.
There are 2 problems:
1. MythDB::GetSetting can't read the dbschemavar during initialisation
because HaveValidDatabase returns false
2. After calling DBUtil::lockSchema mysql requests fail during prepare
with the error that LOCK TABLES wasn't called
This fix allows the dbschemavar to be read by MythDB::GetSetting even if
HaveValidDatabase returns false and disables "LOCK TABLE schemalock WRITE;"
I don't (and hope never will) have the mysql knowledge to fix the table
locking 'properly' so this is an expedient fix.
Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
---
mythtv/libs/libmythbase/dbutil.cpp | 5 ++++-
mythtv/libs/libmythbase/mythdb.cpp | 9 +++++++--
mythtv/libs/libmythtv/dbcheck.cpp | 5 +++--
3 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/mythtv/libs/libmythbase/dbutil.cpp b/mythtv/libs/libmythbase/dbutil.cpp
index b4d70e8..3db2c47 100644
a
|
b
|
bool DBUtil::lockSchema(MSqlQuery &query) |
859 | 859 | return false; |
860 | 860 | } |
861 | 861 | |
| 862 | #if 0 |
862 | 863 | if (!query.exec("LOCK TABLE schemalock WRITE;")) |
863 | 864 | { |
864 | 865 | LOG(VB_GENERAL, LOG_CRIT, |
… |
… |
bool DBUtil::lockSchema(MSqlQuery &query) |
866 | 867 | .arg(MythDB::DBErrorMessage(query.lastError()))); |
867 | 868 | return false; |
868 | 869 | } |
869 | | |
| 870 | #endif |
870 | 871 | return true; |
871 | 872 | } |
872 | 873 | |
873 | 874 | void DBUtil::unlockSchema(MSqlQuery &query) |
874 | 875 | { |
| 876 | #if 0 |
875 | 877 | // Should this _just_ unlock schemalock? |
876 | 878 | if (!query.exec("UNLOCK TABLES;")) |
877 | 879 | MythDB::DBError("unlockSchema -- unlocking tables", query); |
| 880 | #endif |
878 | 881 | } |
879 | 882 | |
880 | 883 | /* vim: set expandtab tabstop=4 shiftwidth=4: */ |
diff --git a/mythtv/libs/libmythbase/mythdb.cpp b/mythtv/libs/libmythbase/mythdb.cpp
index 66d0c9b..d3a8726 100644
a
|
b
|
QString MythDB::GetSetting(const QString &_key, const QString &defaultval) |
371 | 371 | } |
372 | 372 | d->settingsCacheLock.unlock(); |
373 | 373 | |
374 | | if (d->ignoreDatabase || !HaveValidDatabase()) |
| 374 | if (!key.endsWith("dbschemaver") && (d->ignoreDatabase || !HaveValidDatabase())) |
375 | 375 | return value; |
376 | 376 | |
377 | 377 | MSqlQuery query(MSqlQuery::InitCon()); |
… |
… |
QString MythDB::GetSetting(const QString &_key, const QString &defaultval) |
403 | 403 | "WHERE value = :KEY AND hostname IS NULL"); |
404 | 404 | query.bindValue(":KEY", key); |
405 | 405 | |
406 | | if (query.exec() && query.next()) |
| 406 | if (!query.exec()) |
| 407 | { |
| 408 | MythDB::DBError("GetSetting - query failure: ", query); |
| 409 | value = d->m_settings->GetSetting(key, defaultval); |
| 410 | } |
| 411 | else if (query.next()) |
407 | 412 | { |
408 | 413 | value = query.value(0).toString(); |
409 | 414 | } |
diff --git a/mythtv/libs/libmythtv/dbcheck.cpp b/mythtv/libs/libmythtv/dbcheck.cpp
index 9bde639..c31c8ee 100644
a
|
b
|
static bool UpdateDBVersionNumber(const QString &newnumber, QString &dbver) |
384 | 384 | } |
385 | 385 | |
386 | 386 | dbver = newnumber; |
387 | | |
388 | 387 | return true; |
389 | 388 | } |
390 | 389 | |
… |
… |
bool UpgradeTVDatabaseSchema(const bool upgradeAllowed, |
455 | 454 | SchemaUpgradeWizard * DBup; |
456 | 455 | |
457 | 456 | |
458 | | GetMythDB()->SetSuppressDBMessages(true); |
| 457 | // Hiding the db errors isn't a good idea and added significant time |
| 458 | // to tracking down problems during upgrades |
| 459 | // GetMythDB()->SetSuppressDBMessages(true); |
459 | 460 | gCoreContext->ActivateSettingsCache(false); |
460 | 461 | |
461 | 462 | DBup = SchemaUpgradeWizard::Get("DBSchemaVer", "MythTV", |