mirror of
https://github.com/FAUSheppy/open-web-leaderboard.git
synced 2025-12-06 07:01:36 +01:00
fix search with multiple results
This commit is contained in:
24
database.py
24
database.py
@@ -96,17 +96,21 @@ class DatabaseConnection:
|
||||
playerNamePrepared = "%{}%".format(playerName.replace("%", "%%"))
|
||||
cursor.execute("SELECT * FROM players WHERE name == ?", (playerName,))
|
||||
row = cursor.fetchone()
|
||||
|
||||
# if there is exactly one hit for the exact name just return that #
|
||||
if row and not cursor.fetchone():
|
||||
p = player.PlayerInLeaderboard(row)
|
||||
p.rank = self.getPlayerRank(p)
|
||||
return [p]
|
||||
|
||||
playerRows = []
|
||||
cursor.execute("SELECT * FROM players WHERE name LIKE ?", (playerNamePrepared,))
|
||||
for pr in cursor:
|
||||
p = player.PlayerInLeaderboard(pr)
|
||||
p.rank = self.getPlayerRank(p)
|
||||
playerRows += [p]
|
||||
|
||||
playerRow = None
|
||||
if not playerRow:
|
||||
cursor.execute("SELECT * FROM players WHERE name LIKE ?", (playerNamePrepared,))
|
||||
playerRow = cursor.fetchone()
|
||||
if not playerRow:
|
||||
return None
|
||||
|
||||
playerInLeaderboard = player.PlayerInLeaderboard(playerRow)
|
||||
playerInLeaderboard.rank = self.getPlayerRank(playerInLeaderboard)
|
||||
return playerInLeaderboard
|
||||
return playerRows
|
||||
|
||||
def getPlayerRank(self, player):
|
||||
'''Calculate player rank - a player rank may change rapidly and
|
||||
|
||||
Reference in New Issue
Block a user