Ticket #9983: 0001-Fix-upgrade-from-an-empty-database.patch

File 0001-Fix-upgrade-from-an-empty-database.patch, 3.8 KB (added by Lawrence Rust <lvr@…>, 8 years ago)
  • mythtv/libs/libmythbase/dbutil.cpp

    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) 
    859859        return false;
    860860    }
    861861
     862#if 0
    862863    if (!query.exec("LOCK TABLE schemalock WRITE;"))
    863864    {
    864865        LOG(VB_GENERAL, LOG_CRIT,
    bool DBUtil::lockSchema(MSqlQuery &query) 
    866867                        .arg(MythDB::DBErrorMessage(query.lastError())));
    867868        return false;
    868869    }
    869 
     870#endif
    870871    return true;
    871872}
    872873
    873874void DBUtil::unlockSchema(MSqlQuery &query)
    874875{
     876#if 0
    875877    // Should this _just_ unlock schemalock?
    876878    if (!query.exec("UNLOCK TABLES;"))
    877879        MythDB::DBError("unlockSchema -- unlocking tables", query);
     880#endif
    878881}
    879882
    880883/* vim: set expandtab tabstop=4 shiftwidth=4: */
  • mythtv/libs/libmythbase/mythdb.cpp

    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) 
    371371    }
    372372    d->settingsCacheLock.unlock();
    373373
    374     if (d->ignoreDatabase || !HaveValidDatabase())
     374    if (!key.endsWith("dbschemaver") && (d->ignoreDatabase || !HaveValidDatabase()))
    375375        return value;
    376376
    377377    MSqlQuery query(MSqlQuery::InitCon());
    QString MythDB::GetSetting(const QString &_key, const QString &defaultval) 
    403403            "WHERE value = :KEY AND hostname IS NULL");
    404404        query.bindValue(":KEY", key);
    405405
    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())
    407412        {
    408413            value = query.value(0).toString();
    409414        }
  • mythtv/libs/libmythtv/dbcheck.cpp

    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) 
    384384    }
    385385
    386386    dbver = newnumber;
    387 
    388387    return true;
    389388}
    390389
    bool UpgradeTVDatabaseSchema(const bool upgradeAllowed, 
    455454    SchemaUpgradeWizard  * DBup;
    456455
    457456
    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);
    459460    gCoreContext->ActivateSettingsCache(false);
    460461
    461462    DBup = SchemaUpgradeWizard::Get("DBSchemaVer", "MythTV",