<commit_before>import abc

import sqlite3

import Config

class Db(object):

    __metaclass__ = abc.ABCMeta

    def __init__(self):
        self._connection = self.connect()
    
    @abc.abstractmethod
    def connect(self, config_file = None):
        raise NotImplementedError("Called method is not implemented")

    @abc.abstractmethod
    def execute(self, query, params = None):
        raise NotImplementedError("Called method is not implemented")

    @abc.abstractmethod
    def commit(self):
        raise NotImplementedError("Called method is not implemented")

    @abc.abstractmethod
    def close(self):
        raise NotImplementedError("Called method is not implemented")
    


class SQLiteDb(Db):
    def connect(self, config_file):
        conf = Config(config_file)
        cfg = conf.sqlite_options()
        sqlite3.connect(cfg.db_file)

    def execute(self, query, params = None):
        self._connection.execute(query, params)

    def commit(self):
        self._connection.commit()

    def close(self):
        self._connection.close()<commit_msg>Fix various small issues in DB support<commit_after>import abc

import sqlite3

from ebroker.Config import Config


def getDb(config_file = None):
    return SQLiteDb(config_file)


class Db(object):

    __metaclass__ = abc.ABCMeta

    def __init__(self, config_file = None):
        self._config_file = config_file
        self._connection = None # make sure attribute _connection exists
    
    @abc.abstractmethod
    def connect(self):
        raise NotImplementedError("Called method is not implemented")

    @abc.abstractmethod
    def execute(self, query, params = None):
        raise NotImplementedError("Called method is not implemented")

    @abc.abstractmethod
    def commit(self):
        raise NotImplementedError("Called method is not implemented")

    @abc.abstractmethod
    def close(self):
        raise NotImplementedError("Called method is not implemented")
    


class SQLiteDb(Db):

    def __init__(self, config_file = None):
        super(SQLiteDb, self).__init__(config_file)
        conf = Config(config_file)
        cfg = conf.sqlite_options()
        self._db_file = cfg.db_file
    
    def connect(self):
        self._connection =  sqlite3.connect(self._db_file)

    def execute(self, query, params = None):
        if self._connection is None:
            self.connect()
        if params is None:
            self._connection.execute(query)
        else:
            self._connection.execute(query, params)

    def commit(self):
        self._connection.commit()

    def close(self):
        self._connection.close()


def prepare(db = None):
    _db = db
    if _db is None:
        _db = getDb()
    _db.execute(''' 
    CREATE TABLE requests(ticker int, price double, amount int, symbol varchar(10), amount_satisfied int)
    ''')
    
    
{'fraction_non_alphanumeric': 0.0903068340306834, 'fraction_numerical': 0.0020920502092050207, 'mean_word_length': 2.810092961487384, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4563117', 'n_tokens_mistral': 830, 'n_tokens_neox': 809, 'n_words': 218}