diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index fde03b71..42cd986c 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -1672,6 +1672,15 @@ class Database: # street4CheckCallRaiseChance, # street4CheckCallRaiseDone) + def isDuplicate(self, gametypeID, siteHandNo): + dup = False + c = self.get_cursor() + c.execute(self.sql.query['isAlreadyInDB'], (gametypeID, siteHandNo)) + result = c.fetchall() + if len(result) > 0: + dup = True + return dup + def getGameTypeId(self, siteid, game): c = self.get_cursor() #FIXME: Fixed for NL at the moment @@ -1711,6 +1720,13 @@ class Database: q = "SELECT name, id FROM Players WHERE siteid=%s and name=%s" q = q.replace('%s', self.sql.query['placeholder']) + #NOTE/FIXME?: MySQL has ON DUPLICATE KEY UPDATE + #Usage: + # INSERT INTO `tags` (`tag`, `count`) + # VALUES ($tag, 1) + # ON DUPLICATE KEY UPDATE `count`=`count`+1; + + #print "DEBUG: name: %s site: %s" %(name, site_id) c.execute (q, (site_id, name)) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index a5ea87ec..f6fa478e 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -210,24 +210,24 @@ db: a connected fpdb_db object""" ##### # End prep functions ##### - - # HandsActions - all actions for all players for all streets - self.actions - # HudCache data can be generated from HandsActions (HandsPlayers?) - - # Hands - Summary information of hand indexed by handId - gameinfo hh = self.stats.getHands() - hh['gameTypeId'] = gtid - # seats TINYINT NOT NULL, - hh['seats'] = len(sqlids) - #print hh - handid = db.storeHand(hh) - # HandsPlayers - ? ... Do we fix winnings? - db.storeHandsPlayers(handid, sqlids, self.stats.getHandsPlayers()) - # Tourneys ? - # TourneysPlayers + if not db.isDuplicate(gtid, hh['siteHandNo']): + # Hands - Summary information of hand indexed by handId - gameinfo + hh['gameTypeId'] = gtid + # seats TINYINT NOT NULL, + hh['seats'] = len(sqlids) - pass + handid = db.storeHand(hh) + db.storeHandsPlayers(handid, sqlids, self.stats.getHandsPlayers()) + # HandsActions - all actions for all players for all streets - self.actions + # HudCache data can be generated from HandsActions (HandsPlayers?) + # Tourneys ? + # TourneysPlayers + else: + log.info("Hand.insert(): hid #: %s is a duplicate" % hh['siteHandNo']) + #Raise Duplicate exception? + pass def select(self, handId): """ Function to create Hand object from database """