diff options
-rw-r--r-- | xbmc/dbwrappers/Database.cpp | 38 | ||||
-rw-r--r-- | xbmc/dbwrappers/Database.h | 2 |
2 files changed, 25 insertions, 15 deletions
diff --git a/xbmc/dbwrappers/Database.cpp b/xbmc/dbwrappers/Database.cpp index 0d294fe706..55a33a838e 100644 --- a/xbmc/dbwrappers/Database.cpp +++ b/xbmc/dbwrappers/Database.cpp @@ -341,6 +341,26 @@ bool CDatabase::Open(DatabaseSettings &dbSettings) m_bOpen = true; // Database exists, check the version number + if (!UpdateVersion(dbSettings.name)) + { + Close(); + return false; + } + + // sqlite3 post connection operations + if (dbSettings.type.Equals("sqlite3")) + { + m_pDS->exec("PRAGMA cache_size=4096\n"); + m_pDS->exec("PRAGMA synchronous='NORMAL'\n"); + m_pDS->exec("PRAGMA count_changes='OFF'\n"); + } + + m_iRefCount++; + return true; +} + +bool CDatabase::UpdateVersion(const CStdString &dbName) +{ int version = 0; m_pDS->query("SELECT idVersion FROM version\n"); if (m_pDS->num_rows() > 0) @@ -348,32 +368,20 @@ bool CDatabase::Open(DatabaseSettings &dbSettings) if (version < GetMinVersion()) { - CLog::Log(LOGNOTICE, "Attempting to update the database %s from version %i to %i", dbSettings.name.c_str(), version, GetMinVersion()); + CLog::Log(LOGNOTICE, "Attempting to update the database %s from version %i to %i", dbName.c_str(), version, GetMinVersion()); if (UpdateOldVersion(version) && UpdateVersionNumber()) CLog::Log(LOGINFO, "Update to version %i successfull", GetMinVersion()); else { - CLog::Log(LOGERROR, "Can't update the database %s from version %i to %i", dbSettings.name.c_str(), version, GetMinVersion()); - Close(); + CLog::Log(LOGERROR, "Can't update the database %s from version %i to %i", dbName.c_str(), version, GetMinVersion()); return false; } } else if (version > GetMinVersion()) { - CLog::Log(LOGERROR, "Can't open the database %s as it is a NEWER version than what we were expecting!", dbSettings.name.c_str()); - Close(); + CLog::Log(LOGERROR, "Can't open the database %s as it is a NEWER version than what we were expecting?", dbName.c_str()); return false; } - - // sqlite3 post connection operations - if (dbSettings.type.Equals("sqlite3")) - { - m_pDS->exec("PRAGMA cache_size=4096\n"); - m_pDS->exec("PRAGMA synchronous='NORMAL'\n"); - m_pDS->exec("PRAGMA count_changes='OFF'\n"); - } - - m_iRefCount++; return true; } diff --git a/xbmc/dbwrappers/Database.h b/xbmc/dbwrappers/Database.h index e9cf9ff60d..b2c21994ad 100644 --- a/xbmc/dbwrappers/Database.h +++ b/xbmc/dbwrappers/Database.h @@ -114,6 +114,8 @@ protected: virtual int GetMinVersion() const=0; virtual const char *GetDefaultDBName() const=0; + bool UpdateVersion(const CStdString &dbName); + bool m_bOpen; bool m_sqlite; ///< \brief whether we use sqlite (defaults to true) |