TOURNEY: DB.createOrUpdateTourney fills in missing fields now

This commit is contained in:
steffen123 2010-07-14 22:36:07 +02:00
parent 40088d6cf3
commit 85cc5a5471
3 changed files with 32 additions and 10 deletions

View File

@ -2033,12 +2033,31 @@ class Database:
def createOrUpdateTourney(self, hand, source):#note: this method is used on Hand and TourneySummary objects def createOrUpdateTourney(self, hand, source):#note: this method is used on Hand and TourneySummary objects
cursor = self.get_cursor() cursor = self.get_cursor()
cursor.execute (self.sql.query['getTourneyIdByTourneyNo'].replace('%s', self.sql.query['placeholder']), cursor.execute (self.sql.query['getTourneyByTourneyNo'].replace('%s', self.sql.query['placeholder']),
(hand.siteId, hand.tourNo)) (hand.siteId, hand.tourNo))
columnNames=[desc[0] for desc in cursor.description]
result=cursor.fetchone() result=cursor.fetchone()
if result != None and len(result)==1: if result != None:
tourneyId = result[0] expectedValues = ('comment', 'tourneyName', 'matrixIdProcessed', 'totalRebuyCount', 'totalAddOnCount',
'prizepool', 'startTime', 'entries', 'commentTs', 'endTime')
updateDb=False
resultDict = dict(zip(columnNames, result))
tourneyId = resultDict["id"]
if source=="TS":
for ev in expectedValues :
if getattr(hand, ev)==None and resultDict[ev]!=None:#DB has this value but object doesnt, so update object
setattr(hand, ev, resultDict[ev])
elif getattr(hand, ev)!=None and resultDict[ev]==None:#object has this value but DB doesnt, so update DB
updateDb=True
elif ev=="startTime":
if (resultDict[ev] < hand.startTime):
hand.startTime=resultDict[ev]
if updateDb:
cursor.execute (self.sql.query['updateTourney'].replace('%s', self.sql.query['placeholder']),
(hand.entries, hand.prizepool, hand.startTime, hand.endTime, hand.tourneyName,
hand.matrixIdProcessed, hand.totalRebuyCount, hand.totalAddOnCount, hand.comment, hand.commentTs, tourneyId))
else: else:
if source=="HHC": if source=="HHC":
cursor.execute (self.sql.query['insertTourney'].replace('%s', self.sql.query['placeholder']), cursor.execute (self.sql.query['insertTourney'].replace('%s', self.sql.query['placeholder']),
@ -2046,8 +2065,8 @@ class Database:
hand.startTime, None, None, None, None, None)) hand.startTime, None, None, None, None, None))
elif source=="TS": elif source=="TS":
cursor.execute (self.sql.query['insertTourney'].replace('%s', self.sql.query['placeholder']), cursor.execute (self.sql.query['insertTourney'].replace('%s', self.sql.query['placeholder']),
(hand.tourneyTypeId, hand.tourNo, hand.entries, hand.prizepool, (hand.tourneyTypeId, hand.tourNo, hand.entries, hand.prizepool, hand.startTime,
hand.startTime, hand.endTime, hand.tourneyName, hand.matrixIdProcessed, hand.totalRebuyCount, hand.totalAddOnCount)) hand.endTime, hand.tourneyName, hand.matrixIdProcessed, hand.totalRebuyCount, hand.totalAddOnCount))
else: else:
raise FpdbParseError("invalid source in Database.createOrUpdateTourney") raise FpdbParseError("invalid source in Database.createOrUpdateTourney")
tourneyId = self.get_last_insert_id(cursor) tourneyId = self.get_last_insert_id(cursor)

View File

@ -3700,7 +3700,7 @@ class Sql:
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
""" """
self.query['getTourneyIdByTourneyNo'] = """SELECT t.id self.query['getTourneyByTourneyNo'] = """SELECT t.*
FROM Tourneys t FROM Tourneys t
INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id) INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id)
WHERE tt.siteId=%s AND t.siteTourneyNo=%s WHERE tt.siteId=%s AND t.siteTourneyNo=%s
@ -3714,8 +3714,7 @@ class Sql:
""" """
self.query['updateTourney'] = """UPDATE Tourneys self.query['updateTourney'] = """UPDATE Tourneys
SET tourneyTypeId = %s, SET entries = %s,
entries = %s,
prizepool = %s, prizepool = %s,
startTime = %s, startTime = %s,
endTime = %s, endTime = %s,

View File

@ -93,6 +93,8 @@ class TourneySummary(object):
self.isDoubleOrNothing = False self.isDoubleOrNothing = False
self.guarantee = 0 self.guarantee = 0
self.gametype = {'category':None, 'limitType':None} self.gametype = {'category':None, 'limitType':None}
self.comment = None
self.commentTs = None
# Collections indexed by player names # Collections indexed by player names
self.playerIds = {} self.playerIds = {}
@ -151,7 +153,9 @@ class TourneySummary(object):
("SNG", self.isSng), ("SNG", self.isSng),
("SATELLITE", self.isSatellite), ("SATELLITE", self.isSatellite),
("DOUBLE OR NOTHING", self.isDoubleOrNothing), ("DOUBLE OR NOTHING", self.isDoubleOrNothing),
("GUARANTEE", self.guarantee) ("GUARANTEE", self.guarantee),
("COMMENT", self.comment),
("COMMENT TIMESTAMP", self.commentTs)
) )
structs = ( ("PLAYER IDS", self.playerIds), structs = ( ("PLAYER IDS", self.playerIds),