From 9283d7b5792417110eb48b31e50af142d7a6edb8 Mon Sep 17 00:00:00 2001 From: steffen123 Date: Sun, 11 Jul 2010 09:47:05 +0200 Subject: [PATCH] some fixes for handStart rename, fixes for TT.category/limitType, dumpDatabase method and menu entry --- pyfpdb/Database.py | 54 +++++++++++++++++++++++++++++--------- pyfpdb/Hand.py | 2 +- pyfpdb/PokerStarsToFpdb.py | 2 +- pyfpdb/SQL.py | 14 +++++++--- pyfpdb/TourneySummary.py | 4 +-- pyfpdb/fpdb.pyw | 11 ++++++-- 6 files changed, 65 insertions(+), 22 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 71034563..f739c7db 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -290,6 +290,34 @@ class Database: self.connection.rollback() # make sure any locks taken so far are released #end def __init__ + def dumpDatabase(self, filename): + dumpFile = open(filename, 'w') + + result="Database dump version " + str(DB_VERSION)+"\n\n" + + tables=self.cursor.execute(self.sql.query['list_tables']) + tables=self.cursor.fetchall() + dumpFile.write(result) + + for table in tables: + table=table[0] + print "table:", table + result="###################\nTable "+table+"\n###################\n" + rows=self.cursor.execute(self.sql.query['get'+table]) + rows=self.cursor.fetchall() + columnNames=self.cursor.description + if not rows: + result+="empty table\n" + else: + for row in rows: + for columnNumber in range(len(columnNames)): + result+=(" "+columnNames[columnNumber][0]+"="+str(row[columnNumber])+"\n") + result+="\n" + result+="\n" + dumpFile.write(result) + dumpFile.close() + #end def dumpDatabase + # could be used by hud to change hud style def set_hud_style(self, style): self.hud_style = style @@ -1375,17 +1403,17 @@ class Database: c.execute("INSERT INTO Sites (name,code) VALUES ('Carbon', 'CA')") c.execute("INSERT INTO Sites (name,code) VALUES ('PKR', 'PK')") if self.backend == self.SQLITE: - c.execute("""INSERT INTO TourneyTypes (id, siteId, currency, buyin, fee, buyInChips, maxSeats, knockout, - rebuy, addOn, speed, shootout, matrix) - VALUES (NULL, 1, 'USD', 0, 0, 0, 0, 0, 0, 0, NULL, 0, 0);""") + c.execute("""INSERT INTO TourneyTypes (id, siteId, currency, buyin, fee, category, limitType, + buyInChips, maxSeats, knockout, rebuy, addOn, speed, shootout, matrix) + VALUES (NULL, 1, 'USD', 0, 0, "NA", "NA", 0, 0, 0, 0, 0, NULL, 0, 0);""") elif self.backend == self.PGSQL: - c.execute("""insert into TourneyTypes(siteId, currency, buyin, fee, buyInChips, maxSeats, knockout - ,rebuy, addOn, speed, shootout, matrix) - values (1, 'USD', 0, 0, 0, 0, False, False, False, null, False, False);""") + c.execute("""insert into TourneyTypes(siteId, currency, buyin, fee, category, limitType, + buyInChips, maxSeats, knockout, rebuy, addOn, speed, shootout, matrix) + values (1, 'USD', 0, 0, "NA", "NA", 0, 0, False, False, False, null, False, False);""") elif self.backend == self.MYSQL_INNODB: - c.execute("""insert into TourneyTypes(id, siteId, currency, buyin, fee, buyInChips, maxSeats, knockout - ,rebuy, addOn, speed, shootout, matrix) - values (DEFAULT, 1, 'USD', 0, 0, 0, 0, False, False, False, null, False, False);""") + c.execute("""insert into TourneyTypes(id, siteId, currency, buyin, fee, category, limitType, + buyInChips, maxSeats, knockout, rebuy, addOn, speed, shootout, matrix) + values (DEFAULT, 1, 'USD', 0, 0, "NA", "NA", 0, 0, False, False, False, null, False, False);""") #end def fillDefaultData def rebuild_indexes(self, start=None): @@ -1976,11 +2004,11 @@ class Database: except: # Tourney not found : a TourneyTypeId has to be found or created for that specific tourney tourneyTypeIdMatch = False - + if tourneyTypeIdMatch == False : # Check for an existing TTypeId that matches tourney info, if not found create it cursor.execute (self.sql.query['getTourneyTypeId'].replace('%s', self.sql.query['placeholder']), - (hand.siteId, hand.buyinCurrency, hand.buyin, hand.fee, hand.isKO, + (hand.siteId, hand.buyinCurrency, hand.buyin, hand.fee, hand.gametype['category'], hand.gametype['limitType'], hand.isKO, hand.isRebuy, hand.isRebuy, hand.speed, hand.isShootout, hand.isMatrix) ) result=cursor.fetchone() @@ -1989,7 +2017,7 @@ class Database: tourneyTypeId = result[0] except TypeError: #this means we need to create a new entry cursor.execute (self.sql.query['insertTourneyType'].replace('%s', self.sql.query['placeholder']), - (hand.siteId, hand.buyinCurrency, hand.buyin, hand.fee, hand.buyInChips, + (hand.siteId, hand.buyinCurrency, hand.buyin, hand.fee, hand.gametype['category'], hand.gametype['limitType'], hand.buyInChips, hand.isKO, hand.isRebuy, hand.isAddOn, hand.speed, hand.isShootout, hand.isMatrix) ) @@ -2112,7 +2140,7 @@ class HandToWrite: print "htw.init error: " + str(sys.exc_info()) raise # end def __init__ - + def set_all( self, config, settings, base, category, siteTourneyNo, buyin , fee, knockout, entries, prizepool, tourneyStartTime , isTourney, tourneyTypeId, siteID, siteHandNo diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 59311ae5..49553f85 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -1580,7 +1580,7 @@ limit 1""", {'handid':handid}) SELECT h.sitehandno as hid, h.tablename as table, - h.handstart as startTime + h.startTime as startTime FROM hands as h WHERE h.id = %(handid)s diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index 933f9444..d7386e23 100644 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -238,7 +238,7 @@ class PokerStars(HandHistoryConverter): #2008/09/07 06:23:14 ET m1 = self.re_DateTime.finditer(info[key]) # m2 = re.search("(?P[0-9]{4})\/(?P[0-9]{2})\/(?P[0-9]{2})[\- ]+(?P[0-9]+):(?P[0-9]+):(?P[0-9]+)", info[key]) - datetimestr = "2000/01/01 00:00:00" # default used if time not found (stops import crashing, but handstart will be wrong) + datetimestr = "2000/01/01 00:00:00" # default used if time not found (stops import crashing, but startTime will be wrong) for a in m1: datetimestr = "%s/%s/%s %s:%s:%s" % (a.group('Y'), a.group('M'),a.group('D'),a.group('H'),a.group('MIN'),a.group('S')) #tz = a.group('TZ') # just assume ET?? diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index 47c9740f..532cdad3 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -3646,6 +3646,8 @@ class Sql: AND currency=%s AND buyin=%s AND fee=%s + AND category=%s + AND limitType=%s AND knockout=%s AND rebuy=%s AND addOn=%s @@ -3655,9 +3657,9 @@ class Sql: """ self.query['insertTourneyType'] = """INSERT INTO TourneyTypes - (siteId, currency, buyin, fee, buyInChips, knockout, rebuy, + (siteId, currency, buyin, fee, category, limitType, buyInChips, knockout, rebuy, addOn ,speed, shootout, matrix) - VALUES (%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 @@ -3734,7 +3736,7 @@ class Sql: gametypeid, sitehandno, tourneyId, - handstart, + startTime, importtime, seats, maxseats, @@ -3883,6 +3885,12 @@ class Sql: self.query['getTourneyCount'] = "SELECT COUNT(id) FROM Tourneys" self.query['getTourneyTypeCount'] = "SELECT COUNT(id) FROM TourneyTypes" + ################################ + # queries for dumpDatabase + ################################ + for table in (u'Autorates', u'GameTypes', u'Hands', u'HandsActions', u'HandsPlayers', u'HudCache', u'Players', u'Settings', u'Sites', u'TourneyTypes', u'Tourneys', u'TourneysPlayers'): + self.query['get'+table] = u"SELECT * FROM "+table + ################################ # placeholders and substitution stuff ################################ diff --git a/pyfpdb/TourneySummary.py b/pyfpdb/TourneySummary.py index c57a9f0d..75d4bcde 100644 --- a/pyfpdb/TourneySummary.py +++ b/pyfpdb/TourneySummary.py @@ -334,9 +334,9 @@ limit 1""", {'handid':handid}) SELECT h.sitehandno as hid, h.tablename as table, - h.handstart as startTime + h.startTime as startTime FROM - hands as h + Hands as h WHERE h.id = %(handid)s """, {'handid':handid}) res = c.fetchone() diff --git a/pyfpdb/fpdb.pyw b/pyfpdb/fpdb.pyw index 1fa23528..763d3ef1 100755 --- a/pyfpdb/fpdb.pyw +++ b/pyfpdb/fpdb.pyw @@ -336,6 +336,11 @@ class fpdb: diatitle="Database Statistics") #end def dia_database_stats + def dia_dump_db(self, widget, data=None): + self.db.dumpDatabase("database-dump.sql") + #end def dia_database_stats + + # def dia_get_db_root_credentials(self): # """obtains db root credentials from user""" # user, pw=None, None @@ -658,7 +663,8 @@ class fpdb: - + + @@ -696,7 +702,8 @@ class fpdb: ('createtabs', None, 'Create or Recreate _Tables', None, 'Create or Recreate Tables ', self.dia_recreate_tables), ('rebuildhudcache', None, 'Rebuild HUD Cache', None, 'Rebuild HUD Cache', self.dia_recreate_hudcache), ('rebuildindexes', None, 'Rebuild DB Indexes', None, 'Rebuild DB Indexes', self.dia_rebuild_indexes), - ('stats', None, '_Statistics', None, 'View Database Statistics', self.dia_database_stats), + ('databasestats', None, '_Statistics', None, 'View Database Statistics', self.dia_database_stats), + ('dumptofile', None, 'Dump Database to Textfile', None, 'Dump Database to Textfile (takes much time, RAM, HD)', self.dia_dump_db), ('help', None, '_Help'), ('Logs', None, '_Log Messages', None, 'Log and Debug Messages', self.dia_logs), ('About', None, 'A_bout', None, 'About the program', self.dia_about),