diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2010-05-09 21:49:15 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2010-05-09 21:49:15 +0200 |
commit | 1384d1976fa984b6b254c93677363f67944c0c7a (patch) | |
tree | 698faff3ef045df7f2a8e3bd75e6b1e04a397b28 /modules/mysql.py | |
parent | e5cd4bb20328110561ee9956f948b97c378cf671 (diff) | |
download | curunir-1384d1976fa984b6b254c93677363f67944c0c7a.tar curunir-1384d1976fa984b6b254c93677363f67944c0c7a.zip |
Made everything much more error resistant
Diffstat (limited to 'modules/mysql.py')
-rw-r--r-- | modules/mysql.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/modules/mysql.py b/modules/mysql.py index 2db2817..5ae9e93 100644 --- a/modules/mysql.py +++ b/modules/mysql.py @@ -1,10 +1,24 @@ -from base import ModuleBase +from . import ModuleBase import MySQLdb class Module(ModuleBase): def __init__(self, manager): ModuleBase.__init__(self, manager) - conf = manager.config['mysql'] + self.conf = manager.config['mysql'] - self.db = MySQLdb.connect(host = conf['host'], user = conf['user'], passwd = conf['passwd'], db = conf['db'], use_unicode = True, charset = 'utf8') + self.db = False + self._connect() + + def _connect(self): + if self.db: + self.db.close() + self.db = MySQLdb.connect(host = self.conf['host'], user = self.conf['user'], passwd = self.conf['passwd'], db = self.conf['db'], use_unicode = True, charset = 'utf8') + + def cursor(self): + try: + self.db.ping() + return self.db.cursor() + except MySQLdb.OperationalError: + self._connect() + return self.db.cursor() |