aboutsummaryrefslogtreecommitdiffstats
path: root/src/base/UDataBase.pas
diff options
context:
space:
mode:
authorb_krueger <b_krueger@b956fd51-792f-4845-bead-9b4dfca2ff2c>2009-07-18 10:52:29 +0000
committerb_krueger <b_krueger@b956fd51-792f-4845-bead-9b4dfca2ff2c>2009-07-18 10:52:29 +0000
commit92336ab5d99d185d9316330d39a3bb8f881eb9f3 (patch)
tree39249f0f2d571d5913e78bf1c0d846ba074da8d0 /src/base/UDataBase.pas
parent9ceadd2532207fcb512fcfecbd2895055422ad99 (diff)
downloadusdx-92336ab5d99d185d9316330d39a3bb8f881eb9f3.tar.gz
usdx-92336ab5d99d185d9316330d39a3bb8f881eb9f3.tar.xz
usdx-92336ab5d99d185d9316330d39a3bb8f881eb9f3.zip
- Commented delay of error.log in mainloop (error-log is no longer generated without any error)
- If an old 1.01 Ultrastar.db exists, it will no longer deleted on startup, it will be converted into the new 1.1 schema --> added new column in us_songs: rating. This will allow to rate songs in upcoming versions git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1847 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'src/base/UDataBase.pas')
-rw-r--r--src/base/UDataBase.pas50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/base/UDataBase.pas b/src/base/UDataBase.pas
index 0f9d88a7..6691e475 100644
--- a/src/base/UDataBase.pas
+++ b/src/base/UDataBase.pas
@@ -131,6 +131,7 @@ const
procedure TDataBaseSystem.Init(const Filename: string);
var
Version: integer;
+ finalizeConvertion : boolean;
begin
if Assigned(ScoreDB) then
Exit;
@@ -143,24 +144,30 @@ begin
ScoreDB := TSQLiteDatabase.Create(Filename);
fFilename := Filename;
- // Close and delete outdated file
Version := GetVersion();
- if ((Version <> 0) and (Version <> cDBVersion)) then
+
+ if not ScoreDB.TableExists(cUS_Statistics_Info) then
begin
- Log.LogInfo('Outdated cover-database file found', 'TDataBaseSystem.Init');
- // Close and delete outdated file
- ScoreDB.Free;
- if (not DeleteFile(Filename)) then
- raise Exception.Create('Could not delete ' + Filename);
- // Reopen
- ScoreDB := TSQLiteDatabase.Create(Filename);
+ Log.LogInfo('Outdated song-database file found', 'TDataBaseSystem.Init');
Version := 0;
- end;
-
+ //following just works with convertion of usdx1.01 to usdx1.1!
+ //Rename old Tables - to be able to insert new table-structures
+ ScoreDB.ExecSQL('ALTER TABLE US_Scores RENAME TO us_scores_101;');
+ ScoreDB.ExecSQL('ALTER TABLE US_Songs RENAME TO us_songs_101;');
+
+ ScoreDB.ExecSQL('CREATE TABLE IF NOT EXISTS ['+cUS_Statistics_Info+'] (' +
+ '[ResetTime] INTEGER' +
+ ');');
+ // insert creation timestamp
+ ScoreDB.ExecSQL(Format('INSERT INTO ['+cUS_Statistics_Info+'] ' +
+ '([ResetTime]) VALUES(%d);',
+ [DateTimeToUnix(Now())]));
+ finalizeConvertion := true; //means: convertion has to be done!
+ end else finalizeConvertion := false;
+
// Set version number after creation
if (Version = 0) then
SetVersion(cDBVersion);
-
// SQLite does not handle VARCHAR(n) or INT(n) as expected.
// Texts do not have a restricted length, no matter which type is used,
@@ -181,20 +188,21 @@ begin
'[ID] INTEGER PRIMARY KEY, ' +
'[Artist] TEXT NOT NULL, ' +
'[Title] TEXT NOT NULL, ' +
- '[TimesPlayed] INTEGER NOT NULL' +
+ '[TimesPlayed] INTEGER NOT NULL, ' +
+ '[Rating] INTEGER NULL' +
');');
- if not ScoreDB.TableExists(cUS_Statistics_Info) then
+ if finalizeConvertion then
begin
- ScoreDB.ExecSQL('CREATE TABLE IF NOT EXISTS ['+cUS_Statistics_Info+'] (' +
- '[ResetTime] INTEGER' +
- ');');
- // insert creation timestamp
- ScoreDB.ExecSQL(Format('INSERT INTO ['+cUS_Statistics_Info+'] ' +
- '([ResetTime]) VALUES(%d);',
- [DateTimeToUnix(Now())]));
+ //insert old values in new db-schemes (/tables)
+ ScoreDB.ExecSQL('INSERT INTO '+cUS_Scores+' SELECT SongID, Difficulty, Player, Score FROM us_scores_101;');
+ ScoreDB.ExecSQL('INSERT INTO '+cUS_Songs+' SELECT ID, Artist, Title, TimesPlayed, ''NULL'' FROM us_songs_101;');
+ //now drop old tables
+ ScoreDB.ExecSQL('DROP TABLE us_scores_101;');
+ ScoreDB.ExecSQL('DROP TABLE us_songs_101;');
end;
+
except
on E: Exception do
begin