summaryrefslogtreecommitdiff
path: root/jfr_playoff/db.py
diff options
context:
space:
mode:
authorMichaƂ Klichowicz <emkael@tlen.pl>2018-02-23 16:06:59 +0100
committerGitHub <noreply@github.com>2018-02-23 16:06:59 +0100
commit320868f72185630b59cc690e81fbb1f76e92075b (patch)
treea88e5a7aefddac8272e1d3a39c4da6e4db96b5b3 /jfr_playoff/db.py
parent2f4f93417bd0f3f6886a2a04ec0ef2054633d6b3 (diff)
parentcab639df56676443dc7cd8b5ef3dc9ac5dae830b (diff)
Merge pull request #19 from emkael/mysql-import-on-demand
Mysql import on demand
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))