Adjust SQL Query + Making Style a Parameter
Applied query based on lukeIam's suggestion which gives expected data from the database and added style as a parameter based on flokueps suggestion.
This commit is contained in:
1 parent
27d4d21167
commit
8bde612db4
3 files changed
+25
-9
No files matched your search
@@ -85,9 +85,9 @@ namespace Vocaluxe.Base
|
||||
return _HighscoreDB.GetDataBaseSongInfos(artist, title, out numPlayed, out dateAdded, out highscoreID);
|
||||
}
|
||||
|
||||
public static List<SDBScoreEntry> LoadScore(int songID, EGameMode gameMode)
|
||||
public static List<SDBScoreEntry> LoadScore(int songID, EGameMode gameMode, EHighscoreStyle style)
|
||||
{
|
||||
return _HighscoreDB == null ? null : _HighscoreDB.LoadScore(songID, gameMode);
|
||||
return _HighscoreDB == null ? null : _HighscoreDB.LoadScore(songID, gameMode, style);
|
||||
}
|
||||
|
||||
public static int AddScore(SPlayer player)
|
||||
|
||||
@@ -266,7 +266,7 @@ namespace Vocaluxe.Lib.Database
|
||||
return lastInsertID;
|
||||
}
|
||||
|
||||
public List<SDBScoreEntry> LoadScore(int songID, EGameMode gameMode)
|
||||
public List<SDBScoreEntry> LoadScore(int songID, EGameMode gameMode, EHighscoreStyle style)
|
||||
{
|
||||
var scores = new List<SDBScoreEntry>();
|
||||
using (var connection = new SQLiteConnection())
|
||||
@@ -304,13 +304,28 @@ namespace Vocaluxe.Lib.Database
|
||||
if (dataBaseSongID < 0)
|
||||
return scores;
|
||||
|
||||
command.CommandText = "SELECT PlayerName, Score, Date, Difficulty, LineNr, id FROM Scores " +
|
||||
"WHERE [SongID] = @SongID AND [Medley] = @Medley AND [Duet] = @Duet AND [ShortSong] = @ShortSong ";
|
||||
if (CBase.Config.GetHighscoreStyle() == EHighscoreStyle.TR_CONFIG_HIGHSCORE_LIST_BEST)
|
||||
switch (style)
|
||||
{
|
||||
command.CommandText += "GROUP BY PlayerName, Difficulty, LineNr ";
|
||||
case EHighscoreStyle.TR_CONFIG_HIGHSCORE_LIST_BEST:
|
||||
command.CommandText = "SELECT sc.PlayerName, sc.Score, MIN(sc.Date) AS Date, sc.Difficulty, sc.LineNr, sc.id " +
|
||||
"FROM Scores sc " +
|
||||
"INNER JOIN ( " +
|
||||
"SELECT Playername, MAX(Score) AS _Score, Difficulty, LineNr, id " +
|
||||
"FROM Scores " +
|
||||
"WHERE [SongID] = @SongID AND [Medley] = @Medley AND [Duet] = @Duet AND [ShortSong] = @ShortSong " +
|
||||
"GROUP BY PlayerName, Difficulty, LineNr "+
|
||||
") AS mc " +
|
||||
"ON sc.PlayerName = mc.PlayerName AND sc.Difficulty = mc.Difficulty AND sc.LineNr = mc.LineNr AND sc.Score = mc._Score AND sc.id = mc.id " +
|
||||
"GROUP BY sc.PlayerName, sc.Difficulty, sc.LineNr, sc.Score " +
|
||||
"ORDER BY [Score] DESC, [Date] ASC";
|
||||
break;
|
||||
case EHighscoreStyle.TR_CONFIG_HIGHSCORE_LIST_ALL:
|
||||
command.CommandText = "SELECT PlayerName, Score, Date, Difficulty, LineNr, id " +
|
||||
"FROM Scores " +
|
||||
"WHERE [SongID] = @SongID AND [Medley] = @Medley AND [Duet] = @Duet AND [ShortSong] = @ShortSong " +
|
||||
"ORDER BY [Score] DESC, [Date] ASC";
|
||||
break;
|
||||
}
|
||||
command.CommandText += "ORDER BY [Score] DESC, [Date] ASC";
|
||||
|
||||
command.Parameters.Add("@SongID", DbType.Int32, 0).Value = dataBaseSongID;
|
||||
command.Parameters.Add("@Medley", DbType.Int32, 0).Value = medley;
|
||||
|
||||
@@ -239,7 +239,8 @@ namespace Vocaluxe.Screens
|
||||
{
|
||||
int songID = CGame.GetSong(round).ID;
|
||||
EGameMode gameMode = CGame.GetGameMode(round);
|
||||
_Scores[round] = CDataBase.LoadScore(songID, gameMode);
|
||||
EHighscoreStyle style = CBase.Config.GetHighscoreStyle();
|
||||
_Scores[round] = CDataBase.LoadScore(songID, gameMode, style);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user