From f9a805f5cdd1087a5dc09eec45ac06f5219aa6a5 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Wed, 17 Dec 2008 23:03:17 +0000 Subject: [PATCH] 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. --- pyfpdb/GuiPlayerStats.py | 13 +++++++++---- pyfpdb/fpdb_db.py | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/pyfpdb/GuiPlayerStats.py b/pyfpdb/GuiPlayerStats.py index 5a53813f..1f1967e9 100644 --- a/pyfpdb/GuiPlayerStats.py +++ b/pyfpdb/GuiPlayerStats.py @@ -45,13 +45,13 @@ class GuiPlayerStats (threading.Thread): tmp = self.sql.query['playerStats'] result = self.cursor.execute(self.sql.query['getPlayerId'], (self.heroes[self.activesite],)) - result = self.db.cursor.fetchall() + result = self.cursor.fetchall() if not result == (): pid = result[0][0] pid = result[0][0] tmp = tmp.replace("", "(" + str(pid) + ")") self.cursor.execute(tmp) - result = self.db.cursor.fetchall() + result = self.cursor.fetchall() cols = 16 rows = len(result)+1 # +1 for title row 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) l.show() eb.show() + self.fdb.db.commit() + #end def fillStatsFrame(self, vbox): def fillPlayerFrame(self, vbox): for site in self.conf.supported_sites.keys(): @@ -133,9 +135,12 @@ class GuiPlayerStats (threading.Thread): def __init__(self, db, config, querylist, debug=True): self.debug=debug - self.db=db - self.cursor=db.cursor 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 diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index e51538ee..9d619e9a 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -30,6 +30,25 @@ class fpdb_db: self.PGSQL=3 self.SQLITE=4 #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, user=None, password=None):