add do_commit(config) method to fpdb_db.py to make creating
a db connection easier. Used this in guiplayerstats.py to create a separate connection and added commit to stop locks here blocking hand imports.
This commit is contained in:
parent
dd7ede8903
commit
f9a805f5cd
|
@ -45,13 +45,13 @@ class GuiPlayerStats (threading.Thread):
|
||||||
tmp = self.sql.query['playerStats']
|
tmp = self.sql.query['playerStats']
|
||||||
|
|
||||||
result = self.cursor.execute(self.sql.query['getPlayerId'], (self.heroes[self.activesite],))
|
result = self.cursor.execute(self.sql.query['getPlayerId'], (self.heroes[self.activesite],))
|
||||||
result = self.db.cursor.fetchall()
|
result = self.cursor.fetchall()
|
||||||
if not result == ():
|
if not result == ():
|
||||||
pid = result[0][0]
|
pid = result[0][0]
|
||||||
pid = result[0][0]
|
pid = result[0][0]
|
||||||
tmp = tmp.replace("<player_test>", "(" + str(pid) + ")")
|
tmp = tmp.replace("<player_test>", "(" + str(pid) + ")")
|
||||||
self.cursor.execute(tmp)
|
self.cursor.execute(tmp)
|
||||||
result = self.db.cursor.fetchall()
|
result = self.cursor.fetchall()
|
||||||
cols = 16
|
cols = 16
|
||||||
rows = len(result)+1 # +1 for title row
|
rows = len(result)+1 # +1 for title row
|
||||||
self.stats_table = gtk.Table(rows, cols, False)
|
self.stats_table = gtk.Table(rows, cols, False)
|
||||||
|
@ -90,6 +90,8 @@ class GuiPlayerStats (threading.Thread):
|
||||||
self.stats_table.attach(eb, col, col+1, row+1, row+2)
|
self.stats_table.attach(eb, col, col+1, row+1, row+2)
|
||||||
l.show()
|
l.show()
|
||||||
eb.show()
|
eb.show()
|
||||||
|
self.fdb.db.commit()
|
||||||
|
#end def fillStatsFrame(self, vbox):
|
||||||
|
|
||||||
def fillPlayerFrame(self, vbox):
|
def fillPlayerFrame(self, vbox):
|
||||||
for site in self.conf.supported_sites.keys():
|
for site in self.conf.supported_sites.keys():
|
||||||
|
@ -133,9 +135,12 @@ class GuiPlayerStats (threading.Thread):
|
||||||
|
|
||||||
def __init__(self, db, config, querylist, debug=True):
|
def __init__(self, db, config, querylist, debug=True):
|
||||||
self.debug=debug
|
self.debug=debug
|
||||||
self.db=db
|
|
||||||
self.cursor=db.cursor
|
|
||||||
self.conf=config
|
self.conf=config
|
||||||
|
|
||||||
|
# create new db connection to avoid conflicts with other threads
|
||||||
|
self.fdb = fpdb_db.fpdb_db()
|
||||||
|
self.fdb.do_connect(self.conf)
|
||||||
|
self.cursor=self.fdb.cursor
|
||||||
|
|
||||||
self.sql = querylist
|
self.sql = querylist
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,25 @@ class fpdb_db:
|
||||||
self.PGSQL=3
|
self.PGSQL=3
|
||||||
self.SQLITE=4
|
self.SQLITE=4
|
||||||
#end def __init__
|
#end def __init__
|
||||||
|
|
||||||
|
def do_connect(self, config=None):
|
||||||
|
"""Connects a database using information in config"""
|
||||||
|
if config is None:
|
||||||
|
raise FpdbError('Configuration not defined')
|
||||||
|
|
||||||
|
self.settings = {}
|
||||||
|
if (os.sep=="/"):
|
||||||
|
self.settings['os']="linuxmac"
|
||||||
|
else:
|
||||||
|
self.settings['os']="windows"
|
||||||
|
|
||||||
|
self.settings.update(config.get_db_parameters())
|
||||||
|
self.connect(self.settings['db-backend'],
|
||||||
|
self.settings['db-host'],
|
||||||
|
self.settings['db-databaseName'],
|
||||||
|
self.settings['db-user'],
|
||||||
|
self.settings['db-password'])
|
||||||
|
#end def do_connect
|
||||||
|
|
||||||
def connect(self, backend=None, host=None, database=None,
|
def connect(self, backend=None, host=None, database=None,
|
||||||
user=None, password=None):
|
user=None, password=None):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user