From 0dce71da309262fe3591e73d8f0fcfd955b1d5c2 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sat, 19 Jul 2008 16:29:04 +0000 Subject: Some changes in ReadScore and WriteScore to prevent for crashes caused by more than 5 score entrys per song/difficulty git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1216 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UDataBase.pas | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'Game/Code/Classes') diff --git a/Game/Code/Classes/UDataBase.pas b/Game/Code/Classes/UDataBase.pas index bbdce9ec..20b44c75 100644 --- a/Game/Code/Classes/UDataBase.pas +++ b/Game/Code/Classes/UDataBase.pas @@ -155,10 +155,10 @@ begin SetLength (Song.Score[1], 0); SetLength (Song.Score[2], 0); - while not TableData.Eof do //Go through all Entrys + while (not TableData.Eof) do //Go through all Entrys begin //Add one Entry to Array Difficulty := StrToIntDef(TableData.FieldAsString(TableData.FieldIndex['Difficulty']), -1); - if (Difficulty >= 0) AND (Difficulty <= 2) then + if ((Difficulty >= 0) AND (Difficulty <= 2)) AND (Length(Song.Score[Difficulty]) < 5) then begin SetLength(Song.Score[Difficulty], Length(Song.Score[Difficulty]) + 1); @@ -212,13 +212,24 @@ begin //Create new Entry ScoreDB.ExecSQL('INSERT INTO `'+cUS_Scores+'` ( `SongID` , `Difficulty` , `Player` , `Score` ) VALUES ("' + InttoStr(ID) + '", "' + InttoStr(Level) + '", "' + Name + '", "' + InttoStr(Score) + '");'); - //Delete Last Position when there are more than 5 Entrys + {//Old Deletion if ScoreDB.GetTableValue('SELECT COUNT(`SongID`) FROM `'+cUS_Scores+'` WHERE `SongID` = "' + InttoStr(ID) + '" AND `Difficulty` = "' + InttoStr(Level) +'"') > 5 then begin TableData := ScoreDB.GetTable('SELECT `Player`, `Score` FROM `'+cUS_Scores+'` WHERE SongID = "' + InttoStr(ID) + '" AND `Difficulty` = "' + InttoStr(Level) +'" ORDER BY `Score` ASC LIMIT 1'); ScoreDB.ExecSQL('DELETE FROM `US_Scores` WHERE SongID = "' + InttoStr(ID) + '" AND `Difficulty` = "' + InttoStr(Level) +'" AND `Player` = "' + TableData.FieldAsString(TableData.FieldIndex['Player']) + '" AND `Score` = "' + TableData.FieldAsString(TableData.FieldIndex['Score']) + '"'); + end;} + + //Delete Last Position when there are more than 5 Entrys - Fixes Crash when there are > 5 ScoreEntrys + TableData := ScoreDB.GetTable('SELECT `Player`, `Score` FROM `'+cUS_Scores+'` WHERE SongID = "' + InttoStr(ID) + '" AND `Difficulty` = "' + InttoStr(Level) +'" ORDER BY `Score` DESC LIMIT -1 OFFSET 5'); + + While not TableData.Eof do + begin + ScoreDB.ExecSQL('DELETE FROM `US_Scores` WHERE SongID = "' + InttoStr(ID) + '" AND `Difficulty` = "' + InttoStr(Level) +'" AND `Player` = "' + TableData.FieldAsString(TableData.FieldIndex['Player']) + '" AND `Score` = "' + TableData.FieldAsString(TableData.FieldIndex['Score']) + '"'); + + TableData.Next; end; + end; finally //ScoreDB.Free; -- cgit v1.2.3