Revision: 7249
http://svn.sourceforge.net/xbmc/?rev=7249&view=rev
Author: jmarshallnz
Date: 2006-11-26 16:57:46 -0800 (Sun, 26 Nov 2006)
Log Message:
-----------
fixed: Databases with floating point version numbers could have issues (float -> string -> float conversion). Converted all versions to integers. Also dropped backward compatibility for databases from pre-2.0.0.
Modified Paths:
--------------
trunk/XBMC/xbmc/Database.cpp
trunk/XBMC/xbmc/Database.h
trunk/XBMC/xbmc/MusicDatabase.cpp
trunk/XBMC/xbmc/MusicDatabase.h
trunk/XBMC/xbmc/ProgramDatabase.cpp
trunk/XBMC/xbmc/ProgramDatabase.h
trunk/XBMC/xbmc/VideoDatabase.cpp
trunk/XBMC/xbmc/VideoDatabase.h
Modified: trunk/XBMC/xbmc/Database.cpp
===================================================================
--- trunk/XBMC/xbmc/Database.cpp 2006-11-26 21:19:21 UTC (rev 7248)
+++ trunk/XBMC/xbmc/Database.cpp 2006-11-27 00:57:46 UTC (rev 7249)
@@ -99,27 +99,52 @@
else
{ // Database exists, check the version number
m_pDS->query("SELECT * FROM sqlite_master WHERE type = 'table' AND name = 'version'\n");
- float fVersion = 0.0f;
+ int version = 0;
if (m_pDS->num_rows() > 0)
{
m_pDS->close();
m_pDS->query("SELECT idVersion FROM version\n");
if (m_pDS->num_rows() > 0)
- fVersion = m_pDS->fv("idVersion").get_asFloat();
+ {
+//#ifdef PRE_2_1_DATABASE_COMPATIBILITY
+ float fVersion = m_pDS->fv("idVersion").get_asFloat();
+ if (fVersion < m_preV2version)
+ { // old version - drop db completely
+ CLog::Log(LOGERROR, "Unable to open %s (old version?)", m_strDatabaseFile.c_str());
+ Close();
+ ::DeleteFile(strDatabase.c_str());
+ return false;
+ }
+ if (fVersion < 3)
+ {
+ // has to be old version - drop the version table
+ m_pDS->close();
+ CLog::Log(LOGINFO, "dropping version table");
+ m_pDS->exec("drop table version");
+ CLog::Log(LOGINFO, "creating version table");
+ version = 3;
+ m_pDS->exec("CREATE TABLE version (idVersion integer)\n");
+ CStdString strSQL=FormatSQL("INSERT INTO version (idVersion) values(%i)\n", version);
+ m_pDS->exec(strSQL.c_str());
+ }
+ else
+//#endif
+ version = m_pDS->fv("idVersion").get_asInteger();
+ }
}
- if (fVersion < m_fVersion)
+ if (version < m_version)
{
- CLog::Log(LOGNOTICE, "Attempting to update the database %s from version %.2f to %.2f", m_strDatabaseFile.c_str(), fVersion, m_fVersion);
- if (UpdateOldVersion(fVersion) && UpdateVersionNumber())
- CLog::Log(LOGINFO, "Update to version %.2f successfull", m_fVersion);
+ CLog::Log(LOGNOTICE, "Attempting to update the database %s from version %i to %i", m_strDatabaseFile.c_str(), version, m_version);
+ if (UpdateOldVersion(version) && UpdateVersionNumber())
+ CLog::Log(LOGINFO, "Update to version %i successfull", m_version);
else
{
- CLog::Log(LOGERROR, "Can't update the database %s from version %.2f to %.2f", m_strDatabaseFile.c_str(), fVersion, m_fVersion);
+ CLog::Log(LOGERROR, "Can't update the database %s from version %i to %i", m_strDatabaseFile.c_str(), version, m_version);
Close();
return false;
}
}
- else if (fVersion > m_fVersion)
+ else if (version > m_version)
{
CLog::Log(LOGERROR, "Can't open the database %s as it is a NEWER version than what we were expecting!", m_strDatabaseFile.c_str());
Close();
@@ -247,14 +272,14 @@
m_pDS->exec("PRAGMA default_cache_size=16384\n");
CLog::Log(LOGINFO, "creating version table");
- m_pDS->exec("CREATE TABLE version (idVersion float)\n");
- CStdString strSQL=FormatSQL("INSERT INTO version (idVersion) values(%f)\n", m_fVersion);
+ m_pDS->exec("CREATE TABLE version (idVersion integer)\n");
+ CStdString strSQL=FormatSQL("INSERT INTO version (idVersion) values(%i)\n", m_version);
m_pDS->exec(strSQL.c_str());
return true;
}
-bool CDatabase::UpdateOldVersion(float fVersion)
+bool CDatabase::UpdateOldVersion(int version)
{
return false;
}
@@ -263,7 +288,7 @@
{
try
{
- CStdString strSQL=FormatSQL("UPDATE version SET idVersion=%f\n", m_fVersion);
+ CStdString strSQL=FormatSQL("UPDATE version SET idVersion=%i\n", m_version);
m_pDS->exec(strSQL.c_str());
}
catch(...)
Modified: trunk/XBMC/xbmc/Database.h
===================================================================
--- trunk/XBMC/xbmc/Database.h 2006-11-26 21:19:21 UTC (rev 7248)
+++ trunk/XBMC/xbmc/Database.h 2006-11-27 00:57:46 UTC (rev 7249)
@@ -28,14 +28,17 @@
virtual bool CreateTables();
bool m_bOpen;
- float m_fVersion;
+ int m_version;
+//#ifdef PRE_2_1_DATABASE_COMPATIBILITY
+ float m_preV2version;
+//#endif
CStdString m_strDatabaseFile;
auto_ptr<SqliteDatabase> m_pDB;
auto_ptr<Dataset> m_pDS;
auto_ptr<Dataset> m_pDS2;
private:
- virtual bool UpdateOldVersion(float fVersion);
+ virtual bool UpdateOldVersion(int version);
bool UpdateVersionNumber();
int m_iRefCount;
Modified: trunk/XBMC/xbmc/MusicDatabase.cpp
===================================================================
--- trunk/XBMC/xbmc/MusicDatabase.cpp 2006-11-26 21:19:21 UTC (rev 7248)
+++ trunk/XBMC/xbmc/MusicDatabase.cpp 2006-11-27 00:57:46 UTC (rev 7249)
@@ -11,7 +11,8 @@
using namespace DIRECTORY::MUSICDATABASEDIRECTORY;
-#define MUSIC_DATABASE_VERSION 1.6f
+#define MUSIC_DATABASE_OLD_VERSION 1.6f
+#define MUSIC_DATABASE_VERSION 3
#define MUSIC_DATABASE_NAME "MyMusic6.db"
#define RECENTLY_ADDED_LIMIT 25
#define RECENTLY_PLAYED_LIMIT 25
@@ -20,7 +21,8 @@
CMusicDatabase::CMusicDatabase(void)
{
- m_fVersion=MUSIC_DATABASE_VERSION;
+ m_preV2version=MUSIC_DATABASE_OLD_VERSION;
+ m_version=MUSIC_DATABASE_VERSION;
m_strDatabaseFile=MUSIC_DATABASE_NAME;
m_iSongsBeforeCommit = 0;
}
@@ -3307,7 +3309,7 @@
return false;
}
-bool CMusicDatabase::UpdateOldVersion(float fVersion)
+bool CMusicDatabase::UpdateOldVersion(int version)
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
@@ -3315,255 +3317,6 @@
try
{
- if (fVersion < 0.5f)
- { // Version 0 to 0.5 upgrade - we need to add the version table
- CLog::Log(LOGINFO, "creating versions table");
- m_pDS->exec("CREATE TABLE version (idVersion float)\n");
- }
- if (fVersion < 1.0f)
- {
- // version 0.5 to 1.0 upgrade - we need to add the thumbs table + run SetMusicThumbs()
- // on all elements and then produce a new songs table
- // check if we already have a thumbs table (could happen if the code below asserts for whatever reason)
- m_pDS->query("SELECT * FROM sqlite_master WHERE type = 'table' AND name = 'thumb'\n");
- if (m_pDS->num_rows() > 0)
- {
- m_pDS->close();
- }
- else
- { // create it
- CLog::Log(LOGINFO, "create thumbs table");
- m_pDS->exec("CREATE TABLE thumb ( idThumb integer primary key, strThumb text )\n");
- }
- m_pDS->exec("PRAGMA cache_size=8192\n");
- m_pDS->exec("PRAGMA synchronous='NORMAL'\n");
- m_pDS->exec("PRAGMA count_changes='OFF'\n");
- m_pDS2->exec("PRAGMA cache_size=8192\n");
- m_pDS2->exec("PRAGMA synchronous='NORMAL'\n");
- m_pDS2->exec("PRAGMA count_changes='OFF'\n");
- m_bOpen = true;
- // ok, now we need to run through our table + fill in all the thumbs we need
- CGUIDialogProgress *dialog = (CGUIDialogProgress *)m_gWindowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
- if (dialog)
- {
- dialog->SetHeading("Updating old database version");
- dialog->SetLine(0, "");
- dialog->SetLine(1, "");
- dialog->SetLine(2, "");
- dialog->StartModal();
- dialog->SetLine(1, "Creating newly formatted tables");
- dialog->Progress();
- }
- BeginTransaction();
- CLog::Log(LOGINFO, "Creating temporary songs table");
- m_pDS->exec("CREATE TEMPORARY TABLE tempsong ( idSong integer primary key, idAlbum integer, idPath integer, idArtist integer, iNumArtists integer, idGenre integer, iNumGenres integer, strTitle text, iTrack integer, iDuration integer, iYear integer, dwFileNameCRC text, strFileName text, iTimesPlayed integer, iStartOffset integer, iEndOffset integer)\n");
- CLog::Log(LOGINFO, "Copying songs into temporary song table");
- m_pDS->exec("INSERT INTO tempsong SELECT idSong,idAlbum,idPath,idArtist,iNumArtists,idGenre,iNumGenres,strTitle,iTrack,iDuration,iYear,dwFileNameCRC,strFileName,iTimesPlayed,iStartOffset,iEndOffset FROM song");
- CLog::Log(LOGINFO, "Destroying old songs table");
- m_pDS->exec("DROP TABLE song");
- CLog::Log(LOGINFO, "Creating new songs table");
- m_pDS->exec("CREATE TABLE song ( idSong integer primary key, idAlbum integer, idPath integer, idArtist integer, iNumArtists integer, idGenre integer, iNumGenres integer, strTitle text, iTrack integer, iDuration integer, iYear integer, dwFileNameCRC text, strFileName text, iTimesPlayed integer, iStartOffset integer, iEndOffset integer, idThumb integer)\n");
- CLog::Log(LOGINFO, "Copying songs into new songs table");
- m_pDS->exec("INSERT INTO song(idSong,idAlbum,idPath,idArtist,iNumArtists,idGenre,iNumGenres,strTitle,iTrack,iDuration,iYear,dwFileNameCRC,strFileName,iTimesPlayed,iStartOffset,iEndOffset) SELECT * FROM tempsong");
- CLog::Log(LOGINFO, "Deleting temporary songs table");
- m_pDS->exec("DROP TABLE tempsong");
- CommitTransaction();
- BeginTransaction();
- if (dialog)
- {
- dialog->SetLine(0, "Retrieving updated information on songs...");
- dialog->SetLine(1, "");
- }
- CLog::Log(LOGINFO, "Finding thumbs");
- if (!m_pDS2->query("SELECT * from song join album on song.idAlbum = album.idAlbum join path on path.idPath = song.idPath\n"))
- return false;
- if (m_pDS2->num_rows() > 0)
- {
- CStdString strProgress;
- strProgress.Format("Processing %i of %i", 1, m_pDS2->num_rows());
- if (dialog)
- {
- dialog->SetLine(2, strProgress);
- dialog->Progress();
- }
- // turn on thumb caching - mayaswell make it as fast as we can
- g_directoryCache.InitMusicThumbCache();
- // get data from returned rows
- int count = 1;
- while (!m_pDS2->eof())
- {
- if (!(count % 10))
- {
- strProgress.Format("Processing %i of %i", count, m_pDS2->num_rows());
- if (dialog)
- {
- dialog->SetLine(2, strProgress);
- dialog->Progress();
- }
- }
- CSong song;
- // construct a song to be transferred to a fileitem
- song.strAlbum = m_pDS2->fv("album.strAlbum").get_asString();
- song.iTrack = m_pDS2->fv("song.iTrack").get_asLong() ;
- song.iDuration = m_pDS2->fv("song.iDuration").get_asLong() ;
- song.iYear = m_pDS2->fv("song.iYear").get_asLong() ;
- song.strTitle = m_pDS2->fv("song.strTitle").get_asString();
- song.iTimedPlayed = m_pDS2->fv("song.iTimesPlayed").get_asLong();
- song.iStartOffset = m_pDS2->fv("song.iStartOffset").get_asLong();
- song.iEndOffset = m_pDS2->fv("song.iEndOffset").get_asLong();
- // Get filename with full path
- song.strFileName = m_pDS2->fv("path.strPath").get_asString();
- CUtil::AddDirectorySeperator(song.strFileName);
- song.strFileName += m_pDS2->fv("song.strFileName").get_asString();
- // ok, now transfer to a file item and obtain the thumb
- CFileItem item(song);
- item.SetMusicThumb();
- long idSong = m_pDS2->fv("song.idSong").get_asLong();
- // add any found thumb
- CStdString strThumb = item.GetThumbnailImage();
- long lThumb = AddThumb(strThumb);
- CStdString strSQL=FormatSQL("UPDATE song SET idThumb=%i where idSong=%i", lThumb, idSong);
- m_pDS->exec(strSQL.c_str());
- m_pDS2->next();
- count++;
- }
- }
- // cleanup
- m_pDS2->close();
- g_directoryCache.ClearMusicThumbCache();
- CommitTransaction();
- if (dialog) dialog->Close();
-
- }
- if (fVersion < 1.1f)
- {
- // version 1.0 to 1.1 upgrade - we need to create an index on the thumb table
- CLog::Log(LOGINFO, "create thumb index");
- m_pDS->exec("CREATE INDEX idxThumb ON thumb(strThumb)");
- CLog::Log(LOGINFO, "create thumb index successfull");
- fVersion = MUSIC_DATABASE_VERSION;
- }
- if (fVersion < 1.2f)
- {
- // version 1.1 to 1.2 upgrade - we need to add the musicbrainz columns to the song table
- CLog::Log(LOGINFO, "Updating song table with musicbrainz columns");
- BeginTransaction();
- CLog::Log(LOGINFO, "Creating temporary songs table");
- m_pDS->exec("CREATE TEMPORARY TABLE tempsong ( idSong integer primary key, idAlbum integer, idPath integer, idArtist integer, iNumArtists integer, idGenre integer, iNumGenres integer, strTitle text, iTrack integer, iDuration integer, iYear integer, dwFileNameCRC text, strFileName text, iTimesPlayed integer, iStartOffset integer, iEndOffset integer, idThumb integer)\n");
- CLog::Log(LOGINFO, "Copying songs into temporary song table");
- m_pDS->exec("INSERT INTO tempsong SELECT idSong,idAlbum,idPath,idArtist,iNumArtists,idGenre,iNumGenres,strTitle,iTrack,iDuration,iYear,dwFileNameCRC,strFileName,iTimesPlayed,iStartOffset,iEndOffset,idThumb FROM song");
- CLog::Log(LOGINFO, "Destroying old songs table");
- m_pDS->exec("DROP TABLE song");
- CLog::Log(LOGINFO, "Creating new songs table");
- m_pDS->exec("CREATE TABLE song ( idSong integer primary key, idAlbum integer, idPath integer, idArtist integer, iNumArtists integer, idGenre integer, iNumGenres integer, strTitle text, iTrack integer, iDuration integer, iYear integer, dwFileNameCRC text, strFileName text, strMusicBrainzTrackID text, strMusicBrainzArtistID text, strMusicBrainzAlbumID text, strMusicBrainzAlbumArtistID text, strMusicBrainzTRMID text, iTimesPlayed integer, iStartOffset integer, iEndOffset integer, idThumb integer)\n");
- CLog::Log(LOGINFO, "Copying songs into new songs table");
- m_pDS->exec("INSERT INTO song(idSong,idAlbum,idPath,idArtist,iNumArtists,idGenre,iNumGenres,strTitle,iTrack,iDuration,iYear,dwFileNameCRC,strFileName,iTimesPlayed,iStartOffset,iEndOffset,idThumb) SELECT * FROM tempsong");
- CLog::Log(LOGINFO, "Deleting temporary songs table");
- m_pDS->exec("DROP TABLE tempsong");
- CommitTransaction();
- }
- if (fVersion < 1.3f)
- {
- // version 1.2 to 1.3 upgrade - we need to create a date column when a song was played the last time
- CLog::Log(LOGINFO, "Updating song table with lastplayed column");
- BeginTransaction();
- CLog::Log(LOGINFO, "Creating temporary songs table");
- m_pDS->exec("CREATE TEMPORARY TABLE tempsong ( idSong integer primary key, idAlbum integer, idPath integer, idArtist integer, iNumArtists integer, idGenre integer, iNumGenres integer, strTitle text, iTrack integer, iDuration integer, iYear integer, dwFileNameCRC text, strFileName text, strMusicBrainzTrackID text, strMusicBrainzArtistID text, strMusicBrainzAlbumID text, strMusicBrainzAlbumArtistID text, strMusicBrainzTRMID text, iTimesPlayed integer, iStartOffset integer, iEndOffset integer, idThumb integer)\n");
- CLog::Log(LOGINFO, "Copying songs into temporary song table");
- m_pDS->exec("INSERT INTO tempsong SELECT idSong, idAlbum, idPath, idArtist, iNumArtists, idGenre, iNumGenres, strTitle, iTrack, iDuration, iYear, dwFileNameCRC, strFileName, strMusicBrainzTrackID, strMusicBrainzArtistID, strMusicBrainzAlbumID, strMusicBrainzAlbumArtistID, strMusicBrainzTRMID, iTimesPlayed, iStartOffset, iEndOffset, idThumb FROM song");
- CLog::Log(LOGINFO, "Destroying old songs table");
- m_pDS->exec("DROP TABLE song");
- CLog::Log(LOGINFO, "Creating new songs table");
- m_pDS->exec("CREATE TABLE song ( idSong integer primary key, idAlbum integer, idPath integer, idArtist integer, iNumArtists integer, idGenre integer, iNumGenres integer, strTitle text, iTrack integer, iDuration integer, iYear integer, dwFileNameCRC text, strFileName text, strMusicBrainzTrackID text, strMusicBrainzArtistID text, strMusicBrainzAlbumID text, strMusicBrainzAlbumArtistID text, strMusicBrainzTRMID text, iTimesPlayed integer, iStartOffset integer, iEndOffset integer, idThumb integer, lastplayed date)\n");
- CLog::Log(LOGINFO, "Copying songs into new songs table");
- m_pDS->exec("INSERT INTO song(idSong, idAlbum, idPath, idArtist, iNumArtists, idGenre, iNumGenres, strTitle, iTrack, iDuration, iYear, dwFileNameCRC, strFileName, strMusicBrainzTrackID, strMusicBrainzArtistID, strMusicBrainzAlbumID, strMusicBrainzAlbumArtistID, strMusicBrainzTRMID, iTimesPlayed, iStartOffset, iEndOffset, idThumb) SELECT * FROM tempsong");
- CLog::Log(LOGINFO, "Deleting temporary songs table");
- m_pDS->exec("DROP TABLE tempsong");
- CLog::Log(LOGINFO, "create idxSong1 index");
- m_pDS->exec("CREATE INDEX idxSong1 ON song(iTimesPlayed)");
- CLog::Log(LOGINFO, "create idxSong2 index");
- m_pDS->exec("CREATE INDEX idxSong2 ON song(lastplayed)");
- CLog::Log(LOGINFO, "create song view");
- m_pDS->exec("create view songview as select idSong, song.iNumArtists as iNumArtists, song.iNumGenres as iNumGenres, strTitle, iTrack, iDuration, iYear, dwFileNameCRC, strFileName, strMusicBrainzTrackID, strMusicBrainzArtistID, strMusicBrainzAlbumID, strMusicBrainzAlbumArtistID, strMusicBrainzTRMID, iTimesPlayed, iStartOffset, iEndOffset, lastplayed, strAlbum, strPath, strArtist, strGenre, strThumb from song join album on song.idAlbum=album.idAlbum join path on song.idPath=path.idPath join artist on song.idArtist=artist.idArtist join genre on song.idGenre=genre.idGenre join thumb on song.idThumb=thumb.idThumb");
- CLog::Log(LOGINFO, "create album view");
- m_pDS->exec("create view albumview as select idAlbum, strAlbum, iNumArtists, strArtist, strPath from album join path on album.idPath=path.idPath join artist on album.idArtist=artist.idArtist");
- CommitTransaction();
- }
- if (fVersion < 1.4f)
- {
- // version 1.3 to 1.4 upgrade - we need to add a thumbnail column to the album table and update song and album view
- CGUIDialogProgress *dialog = (CGUIDialogProgress *)m_gWindowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
- if (dialog)
- {
- dialog->SetHeading("Updating old database version");
- dialog->SetLine(0, "");
- dialog->SetLine(1, "");
- dialog->SetLine(2, "This may take a couple of minutes...");
- dialog->StartModal();
-
- // Let the progress dialog fade in, hopefully ;)
- DWORD dwTicks=GetTickCount();
- while (GetTickCount()-dwTicks<1000)
- dialog->Progress();
- }
-
- BeginTransaction();
-
- dialog->SetLine(1, "Dropping views...");
- dialog->Progress();
- CLog::Log(LOGINFO, "Dropping song view");
- m_pDS->exec("drop view songview");
- CLog::Log(LOGINFO, "Dropping album view");
- m_pDS->exec("drop view albumview");
-
- dialog->SetLine(1, "Creating new album table...");
- dialog->Progress();
- CLog::Log(LOGINFO, "Creating temporary album table");
- m_pDS->exec("CREATE TEMPORARY TABLE tempalbum ( idAlbum integer primary key, strAlbum text, idArtist integer, iNumArtists integer, idPath integer, idThumb integer)\n");
- CLog::Log(LOGINFO, "Copying albums into temporary album table");
- m_pDS->exec("INSERT INTO tempalbum SELECT distinct album.idAlbum as idAlbum, strAlbum, album.idArtist as idArtist, album.iNumArtists as iNumArtists, album.idPath as idPath, song.idThumb as idThumb FROM album join song on album.idAlbum=song.idAlbum group by album.idalbum");
- CLog::Log(LOGINFO, "Dropping old album table");
- m_pDS->exec("DROP TABLE album");
- CLog::Log(LOGINFO, "Creating new album table");
- m_pDS->exec("CREATE TABLE album ( idAlbum integer primary key, strAlbum text, idArtist integer, iNumArtists integer, idPath integer, idThumb integer)\n");
- CLog::Log(LOGINFO, "Copying albums into new albums table");
- m_pDS->exec("INSERT INTO album(idAlbum, strAlbum, idArtist, iNumArtists, idPath, idThumb) SELECT * FROM tempalbum");
- CLog::Log(LOGINFO, "Dropping temporary album table");
- m_pDS->exec("DROP TABLE tempalbum");
- CLog::Log(LOGINFO, "create album index");
- m_pDS->exec("CREATE INDEX idxAlbum ON album(strAlbum)");
-
- dialog->SetLine(1, "Creating new views...");
- dialog->Progress();
- CLog::Log(LOGINFO, "create song view");
- m_pDS->exec("create view songview as select idSong, song.iNumArtists as iNumArtists, song.iNumGenres as iNumGenres, strTitle, iTrack, iDuration, iYear, dwFileNameCRC, strFileName, strMusicBrainzTrackID, strMusicBrainzArtistID, strMusicBrainzAlbumID, strMusicBrainzAlbumArtistID, strMusicBrainzTRMID, iTimesPlayed, iStartOffset, iEndOffset, lastplayed, song.idAlbum as idAlbum, strAlbum, strPath, song.idArtist as idArtist, strArtist, song.idGenre as idGenre, strGenre, strThumb from song join album on song.idAlbum=album.idAlbum join path on song.idPath=path.idPath join artist on song.idArtist=artist.idArtist join genre on song.idGenre=genre.idGenre join thumb on song.idThumb=thumb.idThumb");
- CLog::Log(LOGINFO, "create album view");
- m_pDS->exec("create view albumview as select idAlbum, strAlbum, iNumArtists, album.idArtist as idArtist, strArtist, strPath, strThumb from album join path on album.idPath=path.idPath join artist on album.idArtist=artist.idArtist join thumb on album.idThumb=thumb.idThumb");
-
- CommitTransaction();
-
- dialog->Close();
- }
- if (fVersion < 1.5f)
- { // version 1.4 to 1.5 upgrade - recreate the album view with
- // left outer instead of inner joins to get albums without an artist
- BeginTransaction();
-
- CLog::Log(LOGINFO, "Dropping album view");
- m_pDS->exec("drop view albumview");
- CLog::Log(LOGINFO, "create album view");
- m_pDS->exec("create view albumview as select idAlbum, strAlbum, iNumArtists, album.idArtist as idArtist, strArtist, strPath, strThumb from album left outer join path on album.idPath=path.idPath left outer join artist on album.idArtist=artist.idArtist left outer join thumb on album.idThumb=thumb.idThumb");
-
- CommitTransaction();
- }
- if (fVersion < 1.6f)
- {
- // upgrade from 1.5 to 1.6 - add partymode table
- BeginTransaction();
- CLog::Log(LOGINFO, "Adding partymode table");
- m_pDS->exec("CREATE TABLE partymode (idRow integer primary key, idSong integer, bRelaxedRestrictions bool)\n");
- CommitTransaction();
- }
}
catch (...)
{
Modified: trunk/XBMC/xbmc/MusicDatabase.h
===================================================================
--- trunk/XBMC/xbmc/MusicDatabase.h 2006-11-26 21:19:21 UTC (rev 7248)
+++ trunk/XBMC/xbmc/MusicDatabase.h 2006-11-27 00:57:46 UTC (rev 7249)
@@ -195,7 +195,7 @@
bool CleanupArtists();
bool CleanupGenres();
bool CleanupAlbumsFromPaths(const CStdString &strPathIds);
- virtual bool UpdateOldVersion(float fVersion);
+ virtual bool UpdateOldVersion(int version);
// Fields should be ordered as they
// appear in the songview
Modified: trunk/XBMC/xbmc/ProgramDatabase.cpp
===================================================================
--- trunk/XBMC/xbmc/ProgramDatabase.cpp 2006-11-26 21:19:21 UTC (rev 7248)
+++ trunk/XBMC/xbmc/ProgramDatabase.cpp 2006-11-27 00:57:46 UTC (rev 7249)
@@ -5,12 +5,14 @@
#include "xbox/xbeheader.h"
#include "GUIWindowFileManager.h"
-#define PROGRAM_DATABASE_VERSION 0.9f
+#define PROGRAM_DATABASE_OLD_VERSION 0.9f
+#define PROGRAM_DATABASE_VERSION 3
//********************************************************************************************************************************
CProgramDatabase::CProgramDatabase(void)
{
- m_fVersion=PROGRAM_DATABASE_VERSION;
+ m_preV2version=PROGRAM_DATABASE_OLD_VERSION;
+ m_version=PROGRAM_DATABASE_VERSION;
m_strDatabaseFile=PROGRAM_DATABASE_NAME;
}
@@ -46,7 +48,7 @@
return true;
}
-bool CProgramDatabase::UpdateOldVersion(float fVersion)
+bool CProgramDatabase::UpdateOldVersion(int version)
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
@@ -54,127 +56,6 @@
try
{
- if (fVersion < 0.5f)
- { // Version 0 to 0.5 upgrade - we need to add the version table
- CLog::Log(LOGINFO, "creating versions table");
- m_pDS->exec("CREATE TABLE version (idVersion float)\n");
- }
-
- if (fVersion < 0.6f)
- { // Version 0.5 to 0.6 upgrade - we need to add the region entry
- CGUIDialogProgress *dialog = (CGUIDialogProgress *)m_gWindowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
- if (dialog)
- {
- dialog->SetHeading("Updating old database version");
- dialog->SetLine(0, "");
- dialog->SetLine(1, "");
- dialog->SetLine(2, "");
- dialog->StartModal();
- dialog->SetLine(1, "Adding table entries");
- dialog->Progress();
- }
- BeginTransaction();
- CLog::Log(LOGINFO, "Creating temporary files table");
- m_pDS->exec("CREATE TABLE tempfiles ( idFile integer primary key, idPath integer, strFilename text, titleId integer, xbedescription text, iTimesPlayed integer, lastAccessed integer)\n");
- CLog::Log(LOGINFO, "Copying files into temporary files table");
- m_pDS->exec("INSERT INTO tempfiles SELECT idFile,idPath,strFilename,titleId,xbedescription,iTimesPlayed,lastAccessed FROM files");
- CLog::Log(LOGINFO, "Destroying old files table");
- m_pDS->exec("DROP TABLE files");
- CLog::Log(LOGINFO, "Creating new files table");
- m_pDS->exec("CREATE TABLE files ( idFile integer primary key, idPath integer, strFilename text, titleId integer, xbedescription text, iTimesPlayed integer, lastAccessed integer, iRegion integer)\n");
- CLog::Log(LOGINFO, "Copying files into new files table");
- m_pDS->exec("INSERT INTO files(idFile,idPath,strFilename,titleId,xbedescription,iTimesPlayed,lastAccessed) SELECT * FROM tempfiles");
- CLog::Log(LOGINFO, "Deleting temporary files table");
- m_pDS->exec("DROP TABLE tempfiles");
-
- CStdString strSQL=FormatSQL("update files set iRegion=%i",-1);
- m_pDS->exec(strSQL.c_str());
-
- CommitTransaction();
- if (dialog) dialog->Close();
- }
- if (fVersion < 0.7f)
- { // Version 0.6 to 0.7 update - need to create the trainers table
- CLog::Log(LOGINFO,"Creating trainers table");
- m_pDS->exec("CREATE TABLE trainers (idKey integer auto_increment primary key, idCRC integer, idTitle integer, strTrainerPath text, strSettings text, Active integer)\n");
- }
- if (fVersion < 0.71f)
- { // Version 0.7 to 0.71 update - fix the idTitle bug
- CGUIDialogProgress *dialog = (CGUIDialogProgress *)m_gWindowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
- if (dialog)
- {
- dialog->SetHeading("Updating old database version");
- dialog->SetLine(0, "");
- dialog->SetLine(1, "Adding table entries");
- dialog->SetLine(2, "");;
- dialog->StartModal();
- dialog->Progress();
- }
- BeginTransaction();
- CLog::Log(LOGINFO, "Creating temporary files table");
- m_pDS->exec("CREATE TABLE tempfiles ( idFile integer primary key, idPath integer, strFilename text, xbedescription text, iTimesPlayed integer, lastAccessed integer, iRegion integer)\n");
- CLog::Log(LOGINFO, "Copying files into temporary files table");
- m_pDS->exec("INSERT INTO tempfiles SELECT idFile,idPath,strFilename,xbedescription,iTimesPlayed,lastAccessed,iRegion FROM files");
- CLog::Log(LOGINFO, "Destroying old files table");
- m_pDS->exec("DROP TABLE files");
- CLog::Log(LOGINFO, "Creating new files table");
- m_pDS->exec("CREATE TABLE files ( idFile integer primary key, idPath integer, strFilename text, titleId integer, xbedescription text, iTimesPlayed integer, lastAccessed integer, iRegion integer)\n");
- CLog::Log(LOGINFO, "Copying files into new files table");
- m_pDS->exec("INSERT INTO files(idFile,idPath,strFilename,xbedescription,iTimesPlayed,lastAccessed,iRegion) SELECT * FROM tempfiles");
- CLog::Log(LOGINFO, "Deleting temporary files table");
- m_pDS->exec("DROP TABLE tempfiles");
-
- CStdString strSQL=FormatSQL("update files set titleId=%i",-1);
- m_pDS->exec(strSQL.c_str());
-
- CommitTransaction();
- if (dialog) dialog->Close();
- }
- if (fVersion < 0.8f)
- { // Version 0.71 to 0.8 update - drop old tables for single files table
- CLog::Log(LOGINFO, "dropping old files table");
- m_pDS->exec("DROP TABLE files");
- CLog::Log(LOGINFO, "creating new files table");
- m_pDS->exec("CREATE TABLE files ( idFile integer primary key, strFilename text, titleId integer, xbedescription text, iTimesPlayed integer, lastAccessed integer, iRegion integer)\n");
- CLog::Log(LOGINFO, "dropping old program table");
- m_pDS->exec("DROP TABLE program");
- CLog::Log(LOGINFO, "dropping bookmark table");
- m_pDS->exec("DROP TABLE bookmark");
- CLog::Log(LOGINFO, "dropping path table");
- m_pDS->exec("DROP TABLE path");
- }
- if (fVersion < 0.9f) // 0.81 was mistake ;)
- { // Version 0.8 to 0.9 update - add size field
- CGUIDialogProgress *dialog = (CGUIDialogProgress *)m_gWindowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
- if (dialog)
- {
- dialog->SetHeading("Updating old database version");
- dialog->SetLine(0, "");
- dialog->SetLine(1, "Adding table entries");
- dialog->SetLine(2, "");;
- dialog->StartModal();
- dialog->Progress();
- }
- BeginTransaction();
- CLog::Log(LOGINFO, "Creating temporary files table");
- m_pDS->exec("CREATE TABLE tempfiles ( idFile integer primary key, strFilename text, titleId integer, xbedescription text, iTimesPlayed integer, lastAccessed integer, iRegion integer)\n");
- CLog::Log(LOGINFO, "Copying files into temporary files table");
- m_pDS->exec("INSERT INTO tempfiles SELECT idFile,strFilename,titleId,xbedescription,iTimesPlayed,lastAccessed,iRegion FROM files");
- CLog::Log(LOGINFO, "Destroying old files table");
- m_pDS->exec("DROP TABLE files");
- CLog::Log(LOGINFO, "Creating new files table");
- m_pDS->exec("CREATE TABLE files ( idFile integer primary key, strFilename text, titleId integer, xbedescription text, iTimesPlayed integer, lastAccessed integer, iRegion integer, iSize integer)\n");
- CLog::Log(LOGINFO, "Copying files into new files table");
- m_pDS->exec("INSERT INTO files(idFile,strFilename,titleId,xbedescription,iTimesPlayed,lastAccessed,iRegion) SELECT * FROM tempfiles");
- CLog::Log(LOGINFO, "Deleting temporary files table");
- m_pDS->exec("DROP TABLE tempfiles");
-
- CStdString strSQL=FormatSQL("update files set iSize=%i",-1);
- m_pDS->exec(strSQL.c_str());
-
- CommitTransaction();
- if (dialog) dialog->Close();
- }
}
catch (...)
{
Modified: trunk/XBMC/xbmc/ProgramDatabase.h
===================================================================
--- trunk/XBMC/xbmc/ProgramDatabase.h 2006-11-26 21:19:21 UTC (rev 7248)
+++ trunk/XBMC/xbmc/ProgramDatabase.h 2006-11-27 00:57:46 UTC (rev 7249)
@@ -38,7 +38,7 @@
protected:
virtual bool CreateTables();
- virtual bool UpdateOldVersion(float fVersion);
+ virtual bool UpdateOldVersion(int version);
FILETIME TimeStampToLocalTime( unsigned __int64 timeStamp );
};
Modified: trunk/XBMC/xbmc/VideoDatabase.cpp
===================================================================
--- trunk/XBMC/xbmc/VideoDatabase.cpp 2006-11-26 21:19:21 UTC (rev 7248)
+++ trunk/XBMC/xbmc/VideoDatabase.cpp 2006-11-27 00:57:46 UTC (rev 7249)
@@ -13,7 +13,8 @@
#include "filesystem/VirtualPathDirectory.h"
#include "filesystem/StackDirectory.h"
-#define VIDEO_DATABASE_VERSION 2.0f
+#define VIDEO_DATABASE_OLD_VERSION 2.0f
+#define VIDEO_DATABASE_VERSION 3
#define VIDEO_DATABASE_NAME "MyVideos31.db"
CBookmark::CBookmark()
@@ -25,7 +26,8 @@
//********************************************************************************************************************************
CVideoDatabase::CVideoDatabase(void)
{
- m_fVersion=VIDEO_DATABASE_VERSION;
+ m_preV2version=VIDEO_DATABASE_OLD_VERSION;
+ m_version=VIDEO_DATABASE_VERSION;
m_strDatabaseFile=VIDEO_DATABASE_NAME;
}
@@ -1642,163 +1644,8 @@
}
}
-bool CVideoDatabase::UpdateOldVersion(float fVersion)
+bool CVideoDatabase::UpdateOldVersion(int version)
{
- if (fVersion < 0.5f)
- { // Version 0 to 0.5 upgrade - we need to add the version table and the settings table
- CLog::Log(LOGINFO, "creating versions table");
- m_pDS->exec("CREATE TABLE version (idVersion float)\n");
-
- CLog::Log(LOGINFO, "create settings table");
- m_pDS->exec("CREATE TABLE settings ( idFile integer, Interleaved bool, NoCache bool, Deinterlace bool, FilmGrain integer,"
- "ViewMode integer,ZoomAmount float, PixelRatio float, AudioStream integer, SubtitleStream integer,"
- "SubtitleDelay float, SubtitlesOn bool, Brightness integer, Contrast integer, Gamma integer,"
- "AdjustFrameRate integer, AudioDelay float)\n");
- }
- // REMOVED: v 1.0 -> 1.2 updates - they just delete the settings table in order
- // to add new settings - mayaswell just delete all the time.
- if (fVersion < 1.3f)
- { // v 1.0 -> 1.3 (new crop settings to video settings table)
- // Just delete and recreate the settings table is the easiest thing to do
- // all it means is per-video settings need recreating on playback - not a big deal
- // and it means the code can be kept reasonably simple.
- CLog::Log(LOGINFO, "Deleting old settings table");
- m_pDS->exec("DROP TABLE settings");
- CLog::Log(LOGINFO, "Creating new settings table");
- m_pDS->exec("CREATE TABLE settings ( idFile integer, Interleaved bool, NoCache bool, Deinterlace bool, FilmGrain integer,"
- "ViewMode integer,ZoomAmount float, PixelRatio float, AudioStream integer, SubtitleStream integer,"
- "SubtitleDelay float, SubtitlesOn bool, Brightness integer, Contrast integer, Gamma integer,"
- "AdjustFrameRate integer, AudioDelay float, ResumeTime integer, Crop bool, CropLeft integer,"
- "CropRight integer, CropTop integer, CropBottom integer)\n");
- }
- if (fVersion < 1.4f)
- { // v 1.3 -> 1.4 (new layout for bookmarks table)
- // Just delete the old bookmarks table and create it fresh
- CLog::Log(LOGINFO, "Deleting old bookmarks table");
- m_pDS->exec("DROP TABLE bookmark");
- CLog::Log(LOGINFO, "Creating new bookmarks table");
- m_pDS->exec("CREATE TABLE bookmark ( idBookmark integer primary key, idFile integer, timeInSeconds integer, thumbNailImage text)\n");
- }
-//*************
-// 2005-10-08
-// MercuryInc
- if (fVersion < 1.5f)
- {
- // v 1.4 -> 1.5 (new layout for Watched tag)
- // Add watched column to movieinfo
- try
- {
- CLog::Log(LOGINFO, "Adding column to movieinfo");
- m_pDS->exec("CREATE TABLE TMPmovieinfo ( idMovie integer, idDirector integer, strPlotOutline text, strPlot text, strTagLine text, strVotes text, strRuntime text, fRating text, strCast text,strCredits text, iYear integer, strGenre text, strPictureURL text, strTitle text, IMDBID text, bWatched bool)\n");
- m_pDS->exec("INSERT INTO TMPmovieinfo SELECT *, 'false' FROM movieinfo\n");
- m_pDS->exec("DROP TABLE movieinfo\n");
- m_pDS->exec("CREATE TABLE movieinfo ( idMovie integer, idDirector integer, strPlotOutline text, strPlot text, strTagLine text, strVotes text, strRuntime text, fRating text, strCast text,strCredits text, iYear integer, strGenre text, strPictureURL text, strTitle text, IMDBID text, bWatched bool)\n");
- m_pDS->exec("INSERT INTO movieinfo SELECT * FROM TMPmovieinfo\n");
- m_pDS->exec("DROP TABLE TMPmovieinfo\n");
- }
- catch (...)
- {
- CLog::Log(LOGERROR, "Failed to add bWatched to movieinfo");
- return false;
- }
-
- //vacuum movieinfo so the db is readable again
- try
- {
- CLog::Log(LOGINFO, "Vacuuming movieinfo");
- m_pDS->exec("VACUUM movieinfo\n");
- }
- catch (...)
- {
- CLog::Log(LOGERROR, "Failed to vacuum movieinfo");
- return false;
- }
- }
-//*************
- if (fVersion < 1.6f)
- {
- // dropping of AdjustFrameRate setting, and addition of VolumeAmplification setting
- CLog::Log(LOGINFO, "Deleting old settings table");
- m_pDS->exec("DROP TABLE settings");
- CLog::Log(LOGINFO, "Creating new settings table");
- m_pDS->exec("CREATE TABLE settings ( idFile integer, Interleaved bool, NoCache bool, Deinterlace bool, FilmGrain integer,"
- "ViewMode integer,ZoomAmount float, PixelRatio float, AudioStream integer, SubtitleStream integer,"
- "SubtitleDelay float, SubtitlesOn bool, Brightness integer, Contrast integer, Gamma integer,"
- "VolumeAmplification float, AudioDelay float, ResumeTime integer, Crop bool, CropLeft integer,"
- "CropRight integer, CropTop integer, CropBottom integer)\n");
- }
-
-//*************
-// 2006-02-20
-// dvdplayer state
- if (fVersion < 1.7f)
- {
- try
- {
- CLog::Log(LOGINFO, "Adding playerState and type to bookmark");
- m_pDS->exec("CREATE TABLE TMPbookmark ( idBookmark integer primary key, idFile integer, timeInSeconds integer, thumbNailImage text, playerState text, type integer)\n");
- m_pDS->exec("INSERT INTO TMPbookmark SELECT idBookmark, idFile, timeInSeconds, thumbNailImage, '', 0 FROM bookmark");
- m_pDS->exec("DROP TABLE bookmark");
- m_pDS->exec("CREATE TABLE bookmark ( idBookmark integer primary key, idFile integer, timeInSeconds integer, thumbNailImage text, playerState text, type integer)\n");
- m_pDS->exec("INSERT INTO bookmark SELECT * FROM TMPbookmark");
- m_pDS->exec("DROP TABLE TMPbookmark");
- }
- catch(...)
- {
- CLog::Log(LOGERROR, "Failed to add playerState and type to bookmark");
- return false;
- }
- }
- if (fVersion < 1.8f)
- {
- // Adding of OutputToAllSpeakers setting
- CLog::Log(LOGINFO, "Deleting old settings table");
- m_pDS->exec("DROP TABLE settings");
- CLog::Log(LOGINFO, "Creating new settings table");
- m_pDS->exec("CREATE TABLE settings ( idFile integer, Interleaved bool, NoCache bool, Deinterlace bool, FilmGrain integer,"
- "ViewMode integer,ZoomAmount float, PixelRatio float, AudioStream integer, SubtitleStream integer,"
- "SubtitleDelay float, SubtitlesOn bool, Brightness integer, Contrast integer, Gamma integer,"
- "VolumeAmplification float, AudioDelay float, OutputToAllSpeakers bool, ResumeTime integer, Crop bool, CropLeft integer,"
- "CropRight integer, CropTop integer, CropBottom integer)\n");
- }
- if (fVersion < 1.9f)
- { // Add the stacktimes table
- try
- {
- CLog::Log(LOGINFO, "Adding stacktimes table");
- m_pDS->exec("CREATE TABLE stacktimes (idFile integer, usingConversions bool, times text)\n");
- }
- catch (...)
- {
- CLog::Log(LOGERROR, "Error adding stacktimes table to the database");
- }
- }
-
-
-//*************
-// 2006-02-20
-// dvdplayer state
- if (fVersion < 2.0f)
- {
- try
- {
- CLog::Log(LOGINFO, "Adding player and changing timeInSeconds to float in bookmark table");
- m_pDS->exec("CREATE TABLE TMPbookmark ( idBookmark integer primary key, idFile integer, timeInSeconds integer, thumbNailImage text, playerState text, type integer)\n");
- m_pDS->exec("INSERT INTO TMPbookmark SELECT idBookmark, idFile, timeInSeconds, thumbNailImage, playerState, type FROM bookmark");
- m_pDS->exec("DROP TABLE bookmark");
- m_pDS->exec("CREATE TABLE bookmark ( idBookmark integer primary key, idFile integer, timeInSeconds double, thumbNailImage text, player text, playerState text, type integer)\n");
- m_pDS->exec("INSERT INTO bookmark SELECT idBookmark, idFile, timeInSeconds, thumbNailImage, '', playerState, type FROM TMPbookmark");
- m_pDS->exec("DROP TABLE TMPbookmark");
- }
- catch(...)
- {
- CLog::Log(LOGERROR, "Failed to upgrade bookmarks");
- return false;
- }
-
- }
-
-
return true;
}
Modified: trunk/XBMC/xbmc/VideoDatabase.h
===================================================================
--- trunk/XBMC/xbmc/VideoDatabase.h 2006-11-26 21:19:21 UTC (rev 7248)
+++ trunk/XBMC/xbmc/VideoDatabase.h 2006-11-27 00:57:46 UTC (rev 7249)
@@ -116,6 +116,6 @@
private:
virtual bool CreateTables();
- virtual bool UpdateOldVersion(float fVersion);
+ virtual bool UpdateOldVersion(int version);
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|