<commit_before># -*- coding: utf-8 -*-
"""Shared database access and functions"""
from __future__ import unicode_literals

from datetime import datetime

import resources.lib.common as common
import resources.lib.database.db_base_mysql as db_base_mysql
import resources.lib.database.db_base_sqlite as db_base_sqlite
import resources.lib.database.db_utils as db_utils
from resources.lib.globals import g


def get_shareddb_class(force_sqlite=False):
    # Dynamically sets the inherit class
    use_mysql = g.ADDON.getSettingBool('use_mysql') and not force_sqlite
    base_class = db_base_mysql.MySQLDatabase if use_mysql else db_base_sqlite.SQLiteDatabase

    class NFSharedDatabase(base_class):
        def __init__(self):
            if use_mysql:
                super(NFSharedDatabase, self).__init__()
            else:
                super(NFSharedDatabase, self).__init__(db_utils.SHARED_DB_FILENAME)

        @db_base_mysql.handle_connection
        @db_base_sqlite.handle_connection
        def set_profile(self, guid, sort_order):
            """Update or Insert a profile"""
            # Update or insert approach,
            # if there is no updated row then insert new one (no id changes)
            if self.is_mysql_database:
                query = db_utils.mysql_insert_or_update('profiles', ['Guid'], ['SortOrder'])
                self._execute_non_query(query, (guid, sort_order), multi=True)
            else:
                data = db_utils.sql_filtered_update('profiles',
                                                    ['SortOrder'],
                                                    ['Guid'],
                                                    [sort_order, guid])
                cur = self._execute_query(data[0], data[1])
                if cur.rowcount == 0:
                    data = db_utils.sql_filtered_insert('profiles',
                                                        ['Guid', 'SortOrder'],
                                                        [guid, sort_order])
                    self._execute_non_query(data[0], data[1])

        @db_base_mysql.handle_connection
        @db_base_sqlite.handle_connection
        def delete_profile(self, guid):
            query = 'DELETE FROM profiles WHERE Guid = ?'
            self._execute_non_query(query, (guid,))

        @db_base_mysql.handle_connection
        @db_base_sqlite.handle_connection<commit_msg>Readded superclass methods to shared db class<commit_after># -*- coding: utf-8 -*-
"""Shared database access and functions"""
from __future__ import unicode_literals

from datetime import datetime

import resources.lib.common as common
import resources.lib.database.db_base_mysql as db_base_mysql
import resources.lib.database.db_base_sqlite as db_base_sqlite
import resources.lib.database.db_utils as db_utils
from resources.lib.globals import g


def get_shareddb_class(force_sqlite=False):
    # Dynamically sets the inherit class
    use_mysql = g.ADDON.getSettingBool('use_mysql') and not force_sqlite
    base_class = db_base_mysql.MySQLDatabase if use_mysql else db_base_sqlite.SQLiteDatabase

    class NFSharedDatabase(base_class):
        def __init__(self):
            if use_mysql:
                super(NFSharedDatabase, self).__init__()
            else:
                super(NFSharedDatabase, self).__init__(db_utils.SHARED_DB_FILENAME)

        def get_value(self, key, default_value=None, table=db_utils.TABLE_SHARED_APP_CONF,
                      data_type=None):
            return super(NFSharedDatabase, self).get_value(key, default_value, table, data_type)

        def get_values(self, key, default_value=None, table=db_utils.TABLE_SHARED_APP_CONF):
            return super(NFSharedDatabase, self).get_values(key, default_value, table)

        def set_value(self, key, value, table=db_utils.TABLE_SHARED_APP_CONF):
            super(NFSharedDatabase, self).set_value(key, value, table)

        def delete_key(self, key, table=db_utils.TABLE_SHARED_APP_CONF):
            super(NFSharedDatabase, self).delete_key(key, table)

        @db_base_mysql.handle_connection
        @db_base_sqlite.handle_connection
        def set_profile(self, guid, sort_order):
            """Update or Insert a profile"""
            # Update or insert approach,
            # if there is no updated row then insert new one (no id changes)
            if self.is_mysql_database:
                query = db_utils.mysql_insert_or_update('profiles', ['Guid'], ['SortOrder'])
                self._execute_non_query(query, (guid, sort_order), multi=True)
            else:
                data = db_utils.sql_filtered_update('profiles',
                                                    ['SortOrder'],
                                                    ['Guid'],
                                                    [sort_order, guid])
                cur = self._execute_query(data[0], data[1])
                if cur.rowcount == 0:
                    data = db_utils.sql_filtered_insert('profiles',
                                                        ['Guid', 'SortOrder'],
                                                        [guid, sort_order])
                    self._execute_non_query(data[0], data[1])

        @db_base_mysql.handle_connection
        @db_base_sqlite.handle_connection
        def delete_profile(self, guid):
            query = 'DELETE FROM profiles WHERE Guid = ?'
            self._execute_non_query(query, (guid,))

        @db_base_mysql.handle_connection
        @db_base_sqlite.handle_connection
{'fraction_non_alphanumeric': 0.08334833483348335, 'fraction_numerical': 0.00216021602160216, 'mean_word_length': 2.0987172336865587, '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': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5431980', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1442, 'n_words': 321}