Skip to content

Commit

Permalink
Fix for disconnected mysql server. Alle remaining sql queries will ge…
Browse files Browse the repository at this point in the history
…t queued! Even blocking sql queries.
  • Loading branch information
derkalle4 committed Sep 29, 2015
1 parent ea62191 commit 4c75137
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions plugins/core/core_TS3db.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
queue = {}
result_queue = {}


def setup(ts3base):
global base
base = ts3base
Expand Down Expand Up @@ -105,20 +104,25 @@ def execute(self, command, type='all'):
Manually executes commands.
Note: If you don't know how to do, please use the pre-formatted query method!
"""
try:
self.cursor = self.connection.cursor(mdb.cursors.DictCursor)
self.cursor.execute(command)
self.connection.commit()
if type is 'all':
tmp = self.cursor.fetchall()
else:
tmp = self.cursor.fetchone()
self.cursor.close()
return tmp
except mdb.Error as e:
self.base.debprint('[MySQL] Error: %d: %s' %
(e.args[0], e.args[1]))
self.cursor.close()
if self.connection is not False:
try:
self.cursor = self.connection.cursor(mdb.cursors.DictCursor)
self.cursor.execute(command)
self.connection.commit()
if type is 'all':
tmp = self.cursor.fetchall()
else:
tmp = self.cursor.fetchone()
self.cursor.close()
return tmp
except mdb.Error as e:
self.base.debprint('[MySQL] Error: %d: %s' %
(e.args[0], e.args[1]))
self.cursor.close()
self.connect()
return False
else:
self.connect()
return False

def query(self, command, type='all', wait=True):
Expand Down Expand Up @@ -149,8 +153,8 @@ def queue_worker(self, event):
qids = queue.copy()
for qid in qids:
tmp = self.execute(queue[qid]['sql'], queue[qid]['type'])
if queue[qid]['wait'] is True:
result_queue[qid] = tmp
del queue[qid]
if len(qids.keys()) > 0:
self.base.debprint('[MySQL] Info: %s queries finished' % len(qids.keys()))
if tmp is not False:
if queue[qid]['wait'] is True:
result_queue[qid] = tmp
del queue[qid]
self.base.debprint('[MySQL] Info: query number %s finished' % qid)

0 comments on commit 4c75137

Please sign in to comment.