summaryrefslogtreecommitdiff
path: root/jfr_playoff/db.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-02-23 10:40:06 +0100
committeremkael <emkael@tlen.pl>2018-02-23 10:40:06 +0100
commitf14ddbc913b3fb278ec48a4004ebce4737b93355 (patch)
tree9f423167fe265032564256aa05b963462bde37ed /jfr_playoff/db.py
parent2f4f93417bd0f3f6886a2a04ec0ef2054633d6b3 (diff)
Getting rid of global mysql imports
Diffstat (limited to 'jfr_playoff/db.py')
-rw-r--r--jfr_playoff/db.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/jfr_playoff/db.py b/jfr_playoff/db.py
index 6825fd2..b7c3726 100644
--- a/jfr_playoff/db.py
+++ b/jfr_playoff/db.py
@@ -1,8 +1,5 @@
import sys
-import mysql.connector
-
-
class PlayoffDB(object):
db_cursor = None
@@ -11,6 +8,7 @@ class PlayoffDB(object):
def __init__(self, settings):
reload(sys)
sys.setdefaultencoding("latin1")
+ import mysql.connector
self.database = mysql.connector.connect(
user=settings['user'],
password=settings['pass'],
@@ -25,11 +23,23 @@ class PlayoffDB(object):
self.db_cursor.execute(sql.replace('#db#', db_name), params)
def fetch(self, db_name, sql, params):
- self.__execute_query(db_name, sql, params)
- row = self.db_cursor.fetchone()
- return row
+ import mysql.connector
+ try:
+ self.__execute_query(db_name, sql, params)
+ row = self.db_cursor.fetchone()
+ return row
+ except mysql.connector.Error as e:
+ raise IOError(
+ message=str(e), filename=db_name,
+ errno=e.errno, strerror=str(e))
def fetch_all(self, db_name, sql, params):
- self.__execute_query(db_name, sql, params)
- results = self.db_cursor.fetchall()
- return results
+ import mysql.connector
+ try:
+ self.__execute_query(db_name, sql, params)
+ results = self.db_cursor.fetchall()
+ return results
+ except mysql.connector.Error as e:
+ raise IOError(
+ message=str(e), filename=db_name,
+ errno=e.errno, strerror=str(e))