summaryrefslogtreecommitdiff
path: root/jfr_playoff/db.py
blob: f7efc7c5c27a32c247ec26ea75f02060e145e3b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import mysql.connector
import sys


class PlayoffDB(object):

    db_cursor = None

    def __init__(self, settings):
        reload(sys)
        sys.setdefaultencoding("latin1")
        self.database = mysql.connector.connect(
            user=settings['user'],
            password=settings['pass'],
            host=settings['host'],
            port=settings['port'])
        self.db_cursor = self.database.cursor(buffered=True)

    def get_cursor(self):
        return self.db_cursor

    def __execute_query(self, db_name, sql, params):
        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

    def fetch_all(self, db_name, sql, params):
        self.__execute_query(db_name, sql, params)
        results = self.db_cursor.fetchall()
        return results