TOURNEY: createOrUpdateTourneysPlayers now updates fields as needed
This commit is contained in:
parent
ced3e8ac72
commit
6a8f3ff68b
|
@ -2084,12 +2084,32 @@ class Database:
|
||||||
raise FpdbParseError("invalid source in Database.createOrUpdateTourneysPlayers")
|
raise FpdbParseError("invalid source in Database.createOrUpdateTourneysPlayers")
|
||||||
|
|
||||||
cursor = self.get_cursor()
|
cursor = self.get_cursor()
|
||||||
cursor.execute (self.sql.query['getTourneysPlayersIdByIds'].replace('%s', self.sql.query['placeholder']),
|
cursor.execute (self.sql.query['getTourneysPlayersByIds'].replace('%s', self.sql.query['placeholder']),
|
||||||
(hand.tourneyId, playerId))
|
(hand.tourneyId, playerId))
|
||||||
|
columnNames=[desc[0] for desc in cursor.description]
|
||||||
result=cursor.fetchone()
|
result=cursor.fetchone()
|
||||||
|
|
||||||
if result != None and len(result)==1:
|
if result != None:
|
||||||
|
expectedValues = ('rank', 'winnings', 'winningsCurrency', 'rebuyCount', 'addOnCount', 'koCount')
|
||||||
|
updateDb=False
|
||||||
|
resultDict = dict(zip(columnNames, result))
|
||||||
|
|
||||||
tourneysPlayersIds.append(result[0])
|
tourneysPlayersIds.append(result[0])
|
||||||
|
if source=="TS":
|
||||||
|
tourneysPlayersId=result[0]
|
||||||
|
for ev in expectedValues :
|
||||||
|
handAttribute=ev
|
||||||
|
if ev!="winnings" and ev!="winningsCurrency":
|
||||||
|
handAttribute+="s"
|
||||||
|
|
||||||
|
if getattr(hand, handAttribute)[player]==None and resultDict[ev]!=None:#DB has this value but object doesnt, so update object
|
||||||
|
setattr(hand, handAttribute, resultDict[ev][player])
|
||||||
|
elif getattr(hand, handAttribute)[player]!=None and resultDict[ev]==None:#object has this value but DB doesnt, so update DB
|
||||||
|
updateDb=True
|
||||||
|
if updateDb:
|
||||||
|
cursor.execute (self.sql.query['updateTourneysPlayer'].replace('%s', self.sql.query['placeholder']),
|
||||||
|
(hand.ranks[player], hand.winnings[player], hand.winningsCurrency[player],
|
||||||
|
hand.rebuyCounts[player], hand.addOnCounts[player], hand.koCounts[player], tourneysPlayersId))
|
||||||
else:
|
else:
|
||||||
if source=="HHC":
|
if source=="HHC":
|
||||||
cursor.execute (self.sql.query['insertTourneysPlayer'].replace('%s', self.sql.query['placeholder']),
|
cursor.execute (self.sql.query['insertTourneysPlayer'].replace('%s', self.sql.query['placeholder']),
|
||||||
|
|
|
@ -3727,20 +3727,18 @@ class Sql:
|
||||||
WHERE id=%s
|
WHERE id=%s
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.query['getTourneysPlayersIdByIds'] = """SELECT id
|
self.query['getTourneysPlayersByIds'] = """SELECT *
|
||||||
FROM TourneysPlayers
|
FROM TourneysPlayers
|
||||||
WHERE tourneyId=%s AND playerId+0=%s
|
WHERE tourneyId=%s AND playerId+0=%s
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.query['updateTourneysPlayers'] = """UPDATE TourneysPlayers
|
self.query['updateTourneysPlayer'] = """UPDATE TourneysPlayers
|
||||||
SET rank = %s,
|
SET rank = %s,
|
||||||
winnings = %s,
|
winnings = %s,
|
||||||
winningsCurrency = %s,
|
winningsCurrency = %s,
|
||||||
rebuyCount = %s,
|
rebuyCount = %s,
|
||||||
addOnCount = %s,
|
addOnCount = %s,
|
||||||
koCount = %s,
|
koCount = %s
|
||||||
comment = %s,
|
|
||||||
commentTs = %s
|
|
||||||
WHERE id=%s
|
WHERE id=%s
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user