aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Marshall <jmarshall@xbmc.org>2014-02-01 15:46:57 +1300
committerJonathan Marshall <jmarshall@xbmc.org>2014-02-06 09:27:33 +1300
commitf576c8da2420103de115cc09ea7bf7bc15c79205 (patch)
treec381f1af0c8472db9b3a3aaec27846c8625d67e3
parent3211effb5e4140b0a4657888c8ed3e281c6b3dc6 (diff)
[cosmetics] rename UpdateOldVersion to UpdateTables for consistency. Drop unneeded try/catch and transaction blocks, make this and UpdateVersionNumber return
void (the dataset classes throw() on errors anyway)
-rw-r--r--xbmc/TextureDatabase.cpp3
-rw-r--r--xbmc/TextureDatabase.h2
-rw-r--r--xbmc/addons/AddonDatabase.cpp3
-rw-r--r--xbmc/addons/AddonDatabase.h2
-rw-r--r--xbmc/dbwrappers/Database.cpp14
-rw-r--r--xbmc/dbwrappers/Database.h8
-rw-r--r--xbmc/epg/EpgDatabase.cpp25
-rw-r--r--xbmc/epg/EpgDatabase.h3
-rw-r--r--xbmc/music/MusicDatabase.cpp27
-rw-r--r--xbmc/music/MusicDatabase.h2
-rw-r--r--xbmc/pvr/PVRDatabase.cpp101
-rw-r--r--xbmc/pvr/PVRDatabase.h3
-rw-r--r--xbmc/video/VideoDatabase.cpp4
-rw-r--r--xbmc/video/VideoDatabase.h2
-rw-r--r--xbmc/view/ViewDatabase.cpp4
-rw-r--r--xbmc/view/ViewDatabase.h2
16 files changed, 70 insertions, 135 deletions
diff --git a/xbmc/TextureDatabase.cpp b/xbmc/TextureDatabase.cpp
index d6544bc209..1905f71332 100644
--- a/xbmc/TextureDatabase.cpp
+++ b/xbmc/TextureDatabase.cpp
@@ -186,7 +186,7 @@ void CTextureDatabase::CreateAnalytics()
m_pDS->exec("CREATE TRIGGER textureDelete AFTER delete ON texture FOR EACH ROW BEGIN delete from sizes where sizes.idtexture=old.id; END");
}
-bool CTextureDatabase::UpdateOldVersion(int version)
+void CTextureDatabase::UpdateTables(int version)
{
if (version < 7)
{ // update all old thumb://foo urls to image://foo?size=thumb
@@ -239,7 +239,6 @@ bool CTextureDatabase::UpdateOldVersion(int version)
m_pDS->exec("CREATE TABLE texture (id integer primary key, url text, cachedurl text, imagehash text, lasthashcheck text)");
m_pDS->exec("CREATE TABLE sizes (idtexture integer, size integer, width integer, height integer, usecount integer, lastusetime text)");
}
- return true;
}
bool CTextureDatabase::IncrementUseCount(const CTextureDetails &details)
diff --git a/xbmc/TextureDatabase.h b/xbmc/TextureDatabase.h
index 8c67844f50..5c4d07ecfe 100644
--- a/xbmc/TextureDatabase.h
+++ b/xbmc/TextureDatabase.h
@@ -125,7 +125,7 @@ protected:
virtual void CreateTables();
virtual void CreateAnalytics();
- virtual bool UpdateOldVersion(int version);
+ virtual void UpdateTables(int version);
virtual int GetMinVersion() const { return 13; };
const char *GetBaseDBName() const { return "Textures"; };
};
diff --git a/xbmc/addons/AddonDatabase.cpp b/xbmc/addons/AddonDatabase.cpp
index 0b8319b38a..7a562a86d7 100644
--- a/xbmc/addons/AddonDatabase.cpp
+++ b/xbmc/addons/AddonDatabase.cpp
@@ -93,7 +93,7 @@ void CAddonDatabase::CreateAnalytics()
m_pDS->exec("CREATE UNIQUE INDEX idxPackage ON package(filename)");
}
-bool CAddonDatabase::UpdateOldVersion(int version)
+void CAddonDatabase::UpdateTables(int version)
{
if (version < 13)
{
@@ -111,7 +111,6 @@ bool CAddonDatabase::UpdateOldVersion(int version)
{
m_pDS->exec("CREATE TABLE package (id integer primary key, addonID text, filename text, hash text)\n");
}
- return true;
}
int CAddonDatabase::AddAddon(const AddonPtr& addon,
diff --git a/xbmc/addons/AddonDatabase.h b/xbmc/addons/AddonDatabase.h
index d303c29c3f..85d40433ad 100644
--- a/xbmc/addons/AddonDatabase.h
+++ b/xbmc/addons/AddonDatabase.h
@@ -137,7 +137,7 @@ public:
protected:
virtual void CreateTables();
virtual void CreateAnalytics();
- virtual bool UpdateOldVersion(int version);
+ virtual void UpdateTables(int version);
virtual int GetMinVersion() const { return 16; }
const char *GetBaseDBName() const { return "Addons"; }
diff --git a/xbmc/dbwrappers/Database.cpp b/xbmc/dbwrappers/Database.cpp
index 9dc04a62dc..00e47ee4c5 100644
--- a/xbmc/dbwrappers/Database.cpp
+++ b/xbmc/dbwrappers/Database.cpp
@@ -531,18 +531,15 @@ bool CDatabase::UpdateVersion(const CStdString &dbName)
else if (version < GetMinVersion())
{
CLog::Log(LOGNOTICE, "Attempting to update the database %s from version %i to %i", dbName.c_str(), version, GetMinVersion());
- bool success = false;
+ bool success = true;
BeginTransaction();
try
{
// drop old analytics, update table(s), recreate analytics, update version
m_pDB->drop_analytics();
- success = UpdateOldVersion(version);
- if (success)
- {
- CreateAnalytics();
- success = UpdateVersionNumber();
- }
+ UpdateTables(version);
+ CreateAnalytics();
+ UpdateVersionNumber();
}
catch (...)
{
@@ -706,11 +703,10 @@ bool CDatabase::CreateDatabase()
return true;
}
-bool CDatabase::UpdateVersionNumber()
+void CDatabase::UpdateVersionNumber()
{
CStdString strSQL=PrepareSQL("UPDATE version SET idVersion=%i\n", GetMinVersion());
m_pDS->exec(strSQL.c_str());
- return true;
}
bool CDatabase::BuildSQL(const CStdString &strQuery, const Filter &filter, CStdString &strSQL)
diff --git a/xbmc/dbwrappers/Database.h b/xbmc/dbwrappers/Database.h
index 073aa3a974..0fdfeed7bf 100644
--- a/xbmc/dbwrappers/Database.h
+++ b/xbmc/dbwrappers/Database.h
@@ -185,7 +185,11 @@ protected:
*/
virtual void CreateAnalytics()=0;
- virtual bool UpdateOldVersion(int version) { return true; };
+ /* \brief Update database tables to the current version.
+ Note that analytics (views, indices, triggers) are not present during this
+ function, so don't rely on them.
+ */
+ virtual void UpdateTables(int version) {};
/* \brief The minimum schema version that we support updating from.
*/
@@ -207,7 +211,7 @@ protected:
private:
void InitSettings(DatabaseSettings &dbSettings);
bool Connect(const CStdString &dbName, const DatabaseSettings &db, bool create);
- bool UpdateVersionNumber();
+ void UpdateVersionNumber();
bool m_bMultiWrite; /*!< True if there are any queries in the queue, false otherwise */
unsigned int m_openCount;
diff --git a/xbmc/epg/EpgDatabase.cpp b/xbmc/epg/EpgDatabase.cpp
index 9208adb1c2..e514649fab 100644
--- a/xbmc/epg/EpgDatabase.cpp
+++ b/xbmc/epg/EpgDatabase.cpp
@@ -89,29 +89,10 @@ void CEpgDatabase::CreateAnalytics()
m_pDS->exec("CREATE INDEX idx_epg_iEndTime on epgtags(iEndTime);");
}
-bool CEpgDatabase::UpdateOldVersion(int iVersion)
+void CEpgDatabase::UpdateTables(int iVersion)
{
- bool bReturn = true;
-
- BeginTransaction();
-
- try
- {
- if (iVersion < 5)
- m_pDS->exec("ALTER TABLE epgtags ADD sGenre varchar(128);");
- }
- catch (...)
- {
- CLog::Log(LOGERROR, "Error attempting to update the database version!");
- bReturn = false;
- }
-
- if (bReturn)
- CommitTransaction();
- else
- RollbackTransaction();
-
- return bReturn;
+ if (iVersion < 5)
+ m_pDS->exec("ALTER TABLE epgtags ADD sGenre varchar(128);");
}
bool CEpgDatabase::DeleteEpg(void)
diff --git a/xbmc/epg/EpgDatabase.h b/xbmc/epg/EpgDatabase.h
index d65af2bd68..c284811fa9 100644
--- a/xbmc/epg/EpgDatabase.h
+++ b/xbmc/epg/EpgDatabase.h
@@ -159,9 +159,8 @@ namespace EPG
/*!
* @brief Update an old version of the database.
* @param version The version to update the database from.
- * @return True if it was updated successfully, false otherwise.
*/
- virtual bool UpdateOldVersion(int version);
+ virtual void UpdateTables(int version);
virtual int GetMinSchemaVersion() const { return 4; }
};
}
diff --git a/xbmc/music/MusicDatabase.cpp b/xbmc/music/MusicDatabase.cpp
index 161aec7bab..ddff546f22 100644
--- a/xbmc/music/MusicDatabase.cpp
+++ b/xbmc/music/MusicDatabase.cpp
@@ -3552,7 +3552,7 @@ bool CMusicDatabase::GetSongsNav(const CStdString& strBaseDir, CFileItemList& it
return GetSongsByWhere(musicUrl.ToString(), filter, items, sortDescription);
}
-bool CMusicDatabase::UpdateOldVersion(int version)
+void CMusicDatabase::UpdateTables(int version)
{
if (version < 16)
{
@@ -3660,11 +3660,7 @@ bool CMusicDatabase::UpdateOldVersion(int version)
strSQL=PrepareSQL("SELECT album.idAlbum AS idAlbum, strExtraArtists,"
" album.idArtist AS idArtist, strArtist FROM album "
" LEFT OUTER JOIN artist ON album.idArtist=artist.idArtist");
- if (!m_pDS->query(strSQL.c_str()))
- {
- CLog::Log(LOGDEBUG, "%s could not upgrade albums table", __FUNCTION__);
- return false;
- }
+ m_pDS->query(strSQL.c_str());
VECALBUMS albums;
while (!m_pDS->eof())
@@ -3706,11 +3702,7 @@ bool CMusicDatabase::UpdateOldVersion(int version)
strSQL=PrepareSQL("SELECT song.idSong AS idSong, strExtraArtists,"
" song.idArtist AS idArtist, strArtist FROM song "
" LEFT OUTER JOIN artist ON song.idArtist=artist.idArtist");
- if (!m_pDS->query(strSQL.c_str()))
- {
- CLog::Log(LOGDEBUG, "%s could not upgrade songs table", __FUNCTION__);
- return false;
- }
+ m_pDS->query(strSQL.c_str());
VECSONGS songs;
while (!m_pDS->eof())
@@ -3752,11 +3744,7 @@ bool CMusicDatabase::UpdateOldVersion(int version)
strSQL=PrepareSQL("SELECT album.idAlbum AS idAlbum, strExtraGenres,"
" album.idGenre AS idGenre, strGenre FROM album "
" JOIN genre ON album.idGenre=genre.idGenre");
- if (!m_pDS->query(strSQL.c_str()))
- {
- CLog::Log(LOGDEBUG, "%s could not upgrade albums table", __FUNCTION__);
- return false;
- }
+ m_pDS->query(strSQL.c_str());
VECALBUMS albums;
while (!m_pDS->eof())
@@ -3798,11 +3786,7 @@ bool CMusicDatabase::UpdateOldVersion(int version)
strSQL=PrepareSQL("SELECT song.idSong AS idSong, strExtraGenres,"
" song.idGenre AS idGenre, strGenre FROM song "
" JOIN genre ON song.idGenre=genre.idGenre");
- if (!m_pDS->query(strSQL.c_str()))
- {
- CLog::Log(LOGDEBUG, "%s could not upgrade songs table", __FUNCTION__);
- return false;
- }
+ m_pDS->query(strSQL.c_str());
VECSONGS songs;
while (!m_pDS->eof())
@@ -4015,7 +3999,6 @@ bool CMusicDatabase::UpdateOldVersion(int version)
m_pDS->exec("UPDATE song_artist SET strJoinPhrase = '' WHERE 100*idSong+iOrder IN (SELECT id FROM (SELECT 100*idSong+max(iOrder) AS id FROM song_artist GROUP BY idSong) AS sub)");
m_pDS->exec("UPDATE album_artist SET strJoinPhrase = '' WHERE 100*idAlbum+iOrder IN (SELECT id FROM (SELECT 100*idAlbum+max(iOrder) AS id FROM album_artist GROUP BY idAlbum) AS sub)");
}
- return true;
}
int CMusicDatabase::GetMinVersion() const
diff --git a/xbmc/music/MusicDatabase.h b/xbmc/music/MusicDatabase.h
index cc579d6409..f2cb33a537 100644
--- a/xbmc/music/MusicDatabase.h
+++ b/xbmc/music/MusicDatabase.h
@@ -497,7 +497,7 @@ private:
bool CleanupAlbums();
bool CleanupArtists();
bool CleanupGenres();
- virtual bool UpdateOldVersion(int version);
+ virtual void UpdateTables(int version);
bool SearchArtists(const CStdString& search, CFileItemList &artists);
bool SearchAlbums(const CStdString& search, CFileItemList &albums);
bool SearchSongs(const CStdString& strSearch, CFileItemList &songs);
diff --git a/xbmc/pvr/PVRDatabase.cpp b/xbmc/pvr/PVRDatabase.cpp
index 798cec2cdf..5110fe65bf 100644
--- a/xbmc/pvr/PVRDatabase.cpp
+++ b/xbmc/pvr/PVRDatabase.cpp
@@ -167,78 +167,57 @@ void CPVRDatabase::CreateAnalytics()
m_pDS->exec("CREATE UNIQUE INDEX idx_idGroup_idChannel on map_channelgroups_channels(idGroup, idChannel);");
}
-bool CPVRDatabase::UpdateOldVersion(int iVersion)
+void CPVRDatabase::UpdateTables(int iVersion)
{
- bool bReturn = true;
+ if (iVersion < 13)
+ m_pDS->exec("ALTER TABLE channels ADD idEpg integer;");
- BeginTransaction();
+ if (iVersion < 14)
+ m_pDS->exec("ALTER TABLE channelsettings ADD fCustomVerticalShift float;");
- try
+ if (iVersion < 15)
+ {
+ m_pDS->exec("ALTER TABLE channelsettings ADD bCustomNonLinStretch bool;");
+ m_pDS->exec("ALTER TABLE channelsettings ADD bPostProcess bool;");
+ m_pDS->exec("ALTER TABLE channelsettings ADD iScalingMethod integer;");
+ }
+ if (iVersion < 16)
+ {
+ /* sqlite apparently can't delete columns from an existing table, so just leave the extra column alone */
+ }
+ if (iVersion < 17)
+ {
+ m_pDS->exec("ALTER TABLE channelsettings ADD iDeinterlaceMode integer");
+ m_pDS->exec("UPDATE channelsettings SET iDeinterlaceMode = 2 WHERE iInterlaceMethod NOT IN (0,1)"); // anything other than none: method auto => mode force
+ m_pDS->exec("UPDATE channelsettings SET iDeinterlaceMode = 1 WHERE iInterlaceMethod = 1"); // method auto => mode auto
+ m_pDS->exec("UPDATE channelsettings SET iDeinterlaceMode = 0, iInterlaceMethod = 1 WHERE iInterlaceMethod = 0"); // method none => mode off, method auto
+ }
+ if (iVersion < 19)
{
+ // bit of a hack, but we need to keep the version/contents of the non-pvr databases the same to allow clean upgrades
+ ADDON::VECADDONS addons;
+ if (!CAddonMgr::Get().GetAddons(ADDON_PVRDLL, addons, true))
+ CLog::Log(LOGERROR, "PVR - %s - failed to get add-ons from the add-on manager", __FUNCTION__);
+ else
{
- if (iVersion < 13)
- m_pDS->exec("ALTER TABLE channels ADD idEpg integer;");
-
- if (iVersion < 14)
- m_pDS->exec("ALTER TABLE channelsettings ADD fCustomVerticalShift float;");
-
- if (iVersion < 15)
- {
- m_pDS->exec("ALTER TABLE channelsettings ADD bCustomNonLinStretch bool;");
- m_pDS->exec("ALTER TABLE channelsettings ADD bPostProcess bool;");
- m_pDS->exec("ALTER TABLE channelsettings ADD iScalingMethod integer;");
- }
- if (iVersion < 16)
- {
- /* sqlite apparently can't delete columns from an existing table, so just leave the extra column alone */
- }
- if (iVersion < 17)
+ CAddonDatabase database;
+ database.Open();
+ for (IVECADDONS it = addons.begin(); it != addons.end(); it++)
{
- m_pDS->exec("ALTER TABLE channelsettings ADD iDeinterlaceMode integer");
- m_pDS->exec("UPDATE channelsettings SET iDeinterlaceMode = 2 WHERE iInterlaceMethod NOT IN (0,1)"); // anything other than none: method auto => mode force
- m_pDS->exec("UPDATE channelsettings SET iDeinterlaceMode = 1 WHERE iInterlaceMethod = 1"); // method auto => mode auto
- m_pDS->exec("UPDATE channelsettings SET iDeinterlaceMode = 0, iInterlaceMethod = 1 WHERE iInterlaceMethod = 0"); // method none => mode off, method auto
+ if (!database.IsSystemPVRAddonEnabled(it->get()->ID()))
+ CAddonMgr::Get().DisableAddon(it->get()->ID());
}
- if (iVersion < 19)
- {
- // bit of a hack, but we need to keep the version/contents of the non-pvr databases the same to allow clean upgrades
- ADDON::VECADDONS addons;
- if ((bReturn = CAddonMgr::Get().GetAddons(ADDON_PVRDLL, addons, true)) == false)
- CLog::Log(LOGERROR, "PVR - %s - failed to get add-ons from the add-on manager", __FUNCTION__);
- else
- {
- CAddonDatabase database;
- database.Open();
- for (IVECADDONS it = addons.begin(); it != addons.end(); it++)
- {
- if (!database.IsSystemPVRAddonEnabled(it->get()->ID()))
- CAddonMgr::Get().DisableAddon(it->get()->ID());
- }
- database.Close();
- }
- }
- if (iVersion < 20)
- m_pDS->exec("ALTER TABLE channels ADD bIsUserSetIcon bool");
-
- if (iVersion < 21)
- m_pDS->exec("ALTER TABLE channelgroups ADD iGroupType integer");
-
- if (iVersion < 22)
- m_pDS->exec("ALTER TABLE channels ADD bIsLocked bool");
+ database.Close();
}
}
- catch (...)
- {
- CLog::Log(LOGERROR, "PVR - %s - error attempting to update the database version!", __FUNCTION__);
- bReturn = false;
- }
+ if (iVersion < 20)
+ m_pDS->exec("ALTER TABLE channels ADD bIsUserSetIcon bool");
- if (bReturn)
- CommitTransaction();
- else
- RollbackTransaction();
+ if (iVersion < 21)
+ m_pDS->exec("ALTER TABLE channelgroups ADD iGroupType integer");
- return bReturn;
+ if (iVersion < 22)
+ m_pDS->exec("ALTER TABLE channels ADD bIsLocked bool");
}
int CPVRDatabase::GetLastChannelId(void)
diff --git a/xbmc/pvr/PVRDatabase.h b/xbmc/pvr/PVRDatabase.h
index 6041abe930..7d28e93772 100644
--- a/xbmc/pvr/PVRDatabase.h
+++ b/xbmc/pvr/PVRDatabase.h
@@ -234,9 +234,8 @@ namespace PVR
/*!
* @brief Update an old version of the database.
* @param version The version to update the database from.
- * @return True if it was updated successfully, false otherwise.
*/
- bool UpdateOldVersion(int version);
+ void UpdateTables(int version);
int GetMinSchemaVersion() { return 11; }
bool PersistGroupMembers(CPVRChannelGroup &group);
diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp
index 3dd437c423..ad8737c177 100644
--- a/xbmc/video/VideoDatabase.cpp
+++ b/xbmc/video/VideoDatabase.cpp
@@ -4147,7 +4147,7 @@ public:
string media_type;
};
-bool CVideoDatabase::UpdateOldVersion(int iVersion)
+void CVideoDatabase::UpdateTables(int iVersion)
{
if (iVersion < 43)
{
@@ -4446,8 +4446,6 @@ bool CVideoDatabase::UpdateOldVersion(int iVersion)
}
if (iVersion < 77)
m_pDS->exec("ALTER TABLE streamdetails ADD strStereoMode text");
-
- return true;
}
int CVideoDatabase::GetMinVersion() const
diff --git a/xbmc/video/VideoDatabase.h b/xbmc/video/VideoDatabase.h
index a09d63bac1..fbd23ee226 100644
--- a/xbmc/video/VideoDatabase.h
+++ b/xbmc/video/VideoDatabase.h
@@ -787,7 +787,7 @@ protected:
private:
virtual void CreateTables();
virtual void CreateAnalytics();
- virtual bool UpdateOldVersion(int version);
+ virtual void UpdateTables(int version);
/*! \brief (Re)Create the generic database views for movies, tvshows,
episodes and music videos
diff --git a/xbmc/view/ViewDatabase.cpp b/xbmc/view/ViewDatabase.cpp
index ea2d919b36..3467fd678d 100644
--- a/xbmc/view/ViewDatabase.cpp
+++ b/xbmc/view/ViewDatabase.cpp
@@ -69,7 +69,7 @@ void CViewDatabase::CreateAnalytics()
m_pDS->exec("CREATE INDEX idxViewsWindow ON view(window)");
}
-bool CViewDatabase::UpdateOldVersion(int version)
+void CViewDatabase::UpdateTables(int version)
{
if (version < 4)
m_pDS->exec("alter table view add skin text");
@@ -128,8 +128,6 @@ bool CViewDatabase::UpdateOldVersion(int version)
}
m_pDS->exec("DROP TABLE tmp_view");
}
-
- return true;
}
bool CViewDatabase::GetViewState(const CStdString &path, int window, CViewState &state, const CStdString &skin)
diff --git a/xbmc/view/ViewDatabase.h b/xbmc/view/ViewDatabase.h
index 3ff554febf..838bdfa326 100644
--- a/xbmc/view/ViewDatabase.h
+++ b/xbmc/view/ViewDatabase.h
@@ -36,7 +36,7 @@ public:
protected:
virtual void CreateTables();
virtual void CreateAnalytics();
- virtual bool UpdateOldVersion(int version);
+ virtual void UpdateTables(int version);
virtual int GetMinVersion() const { return 6; };
const char *GetBaseDBName() const { return "ViewModes"; };
};