TOURNEY: createOrUpdateTourneysPlayers now updates fields as needed

This commit is contained in:
steffen123 2010-07-14 23:05:37 +02:00
parent ced3e8ac72
commit 6a8f3ff68b
2 changed files with 25 additions and 7 deletions

View File

@ -2084,12 +2084,32 @@ class Database:
raise FpdbParseError("invalid source in Database.createOrUpdateTourneysPlayers")
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))
columnNames=[desc[0] for desc in cursor.description]
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])
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:
if source=="HHC":
cursor.execute (self.sql.query['insertTourneysPlayer'].replace('%s', self.sql.query['placeholder']),

View File

@ -3727,20 +3727,18 @@ class Sql:
WHERE id=%s
"""
self.query['getTourneysPlayersIdByIds'] = """SELECT id
self.query['getTourneysPlayersByIds'] = """SELECT *
FROM TourneysPlayers
WHERE tourneyId=%s AND playerId+0=%s
"""
self.query['updateTourneysPlayers'] = """UPDATE TourneysPlayers
self.query['updateTourneysPlayer'] = """UPDATE TourneysPlayers
SET rank = %s,
winnings = %s,
winningsCurrency = %s,
rebuyCount = %s,
addOnCount = %s,
koCount = %s,
comment = %s,
commentTs = %s
koCount = %s
WHERE id=%s
"""