some fixes for handStart rename, fixes for TT.category/limitType,

dumpDatabase method and menu entry
This commit is contained in:
steffen123 2010-07-11 09:47:05 +02:00
parent 5fee5136a9
commit 9283d7b579
6 changed files with 65 additions and 22 deletions

View File

@ -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

View File

@ -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

View File

@ -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<Y>[0-9]{4})\/(?P<M>[0-9]{2})\/(?P<D>[0-9]{2})[\- ]+(?P<H>[0-9]+):(?P<MIN>[0-9]+):(?P<S>[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??

View File

@ -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
################################

View File

@ -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()

View File

@ -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:
<menuitem action="createtabs"/>
<menuitem action="rebuildhudcache"/>
<menuitem action="rebuildindexes"/>
<menuitem action="stats"/>
<menuitem action="databasestats"/>
<menuitem action="dumptofile"/>
</menu>
<menu action="help">
<menuitem action="Logs"/>
@ -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),