Skip to content

Commit

Permalink
Changed PyMySQL to MySQLdb to improve thread compatibility. Seems to …
Browse files Browse the repository at this point in the history
…work better now. We will have to test changes to make sure all works well
  • Loading branch information
derkalle4 committed May 30, 2015
1 parent 6108ae2 commit d7c452e
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions plugins/core_TS3db.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from ts3tools import ts3tools
import pymysql
import MySQLdb as mdb

""" Changelog
-------------
3. kandru - changed pymysql to mysqlclient
2. kandru - changed python cursor to dict cursor (to use column names instead of numbers that can change and break things easier)
1. j0nnib0y - initial commit
"""
Expand Down Expand Up @@ -40,14 +41,17 @@ def connect(self):
Do not use it because it's called at database core init automatically!
"""
try:
self.connection = pymysql.connect(self.config['MySQL']['host'], self.config[
mdb.threadsafety = 3
self.connection = mdb.connect(self.config['MySQL']['host'], self.config[
'MySQL']['user'], self.config['MySQL']['pass'], self.config['MySQL']['db'])
except pymysql.Error as e:
except mdb.Error as e:
self.base.debprint("[MySQL] Error %d: %s" % (e.args[0], e.args[1]))
self.connection = False
return False
if self.connection is not False:
self.cursor = self.connection.cursor(pymysql.cursors.DictCursor)
self.cursor = self.connection.cursor(mdb.cursors.DictCursor)
self.cursor.execute('SELECT VERSION()')
self.base.debprint('[MySQL] Version: %s' % (self.fetch_one()['VERSION()']))
return True
# database schema
# note: there are no global database tables because therefore you can use config files ;)
Expand Down Expand Up @@ -81,15 +85,15 @@ def create_table(self, plugin_name, columns, table_name=None):
try:
self.cursor.execute('CREATE TABLE IF NOT EXISTS `' + self.get_table_name(plugin_name, table_name) + '`' + columnstring + ';')
return True
except pymysql.Error as e:
except mdb.Error as e:
self.base.debprint(
'[MySQL] Error %d: %s' % (e.args[0], e.args[1]))
return False
else:
try:
self.cursor.execute('CREATE TABLE IF NOT EXISTS `' + self.get_table_name(plugin_name) + '`' + columnstring + ';')
return True
except pymysql.Error as e:
except mdb.Error as e:
self.base.debprint(
'[MySQL] Error %d: %s' % (e.args[0], e.args[1]))
return False
Expand All @@ -103,13 +107,19 @@ def execute(self, command):
self.cursor.execute(command)
self.connection.commit()
return True
except pymysql.Error as e:
except mdb.Error as e:
self.base.debprint('[MySQL] Error: %d: %s' %
(e.args[0], e.args[1]))
return False

def fetch_one(self):
return self.cursor.fetchone()
tmp = self.cursor.fetchone()
self.cursor.close()
self.cursor = self.connection.cursor(mdb.cursors.DictCursor)
return tmp

def fetch_all(self):
return self.cursor.fetchall()
tmp = self.cursor.fetchall()
self.cursor.close()
self.cursor = self.connection.cursor(mdb.cursors.DictCursor)
return tmp

0 comments on commit d7c452e

Please sign in to comment.