From 6a8f3ff68b20e9dbf49aa1c63adf9be76ba2279c Mon Sep 17 00:00:00 2001 From: steffen123 Date: Wed, 14 Jul 2010 23:05:37 +0200 Subject: [PATCH] TOURNEY: createOrUpdateTourneysPlayers now updates fields as needed --- pyfpdb/Database.py | 24 ++++++++++++++++++++++-- pyfpdb/SQL.py | 8 +++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 358aed8b..d176bd87 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -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']), diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index afac2d90..5041ae35 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -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 """