<commit_before># -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import struct
import threading
from sqlite3 import sqlite_version_info

from synapse.storage.prepare_database import prepare_database


class Sqlite3Engine(object):
    single_threaded = True

    def __init__(self, database_module, database_config):
        self.module = database_module

        # The current max state_group, or None if we haven't looked
        # in the DB yet.
        self._current_state_group_id = None
        self._current_state_group_id_lock = threading.Lock()

    @property
    def can_native_upsert(self):
        """
        Do we support native UPSERTs? This requires SQLite3 3.24+, plus some
        more work we haven't done yet to tell what was inserted vs updated.
        """
        return sqlite_version_info >= (3, 24, 0)

    def check_database(self, txn):
        pass

    def convert_param_style(self, sql):
        return sql

    def on_new_connection(self, db_conn):
        prepare_database(db_conn, self, config=None)
        db_conn.create_function("rank", 1, _rank)

    def is_deadlock(self, error):
        return False
<commit_msg>Disable native upserts for sqlite, as they don't work<commit_after># -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import struct
import threading
from sqlite3 import sqlite_version_info

from synapse.storage.prepare_database import prepare_database


class Sqlite3Engine(object):
    single_threaded = True

    def __init__(self, database_module, database_config):
        self.module = database_module

        # The current max state_group, or None if we haven't looked
        # in the DB yet.
        self._current_state_group_id = None
        self._current_state_group_id_lock = threading.Lock()

    @property
    def can_native_upsert(self):
        """
        Do we support native UPSERTs?
        """
        # SQLite3 3.24+ supports them, but empirically the unit tests don't work
        # when its enabled.
        # FIXME: Figure out what is wrong so we can re-enable native upserts

        # return sqlite_version_info >= (3, 24, 0)
        return False

    def check_database(self, txn):
        pass

    def convert_param_style(self, sql):
        return sql

    def on_new_connection(self, db_conn):
        prepare_database(db_conn, self, config=None)
        db_conn.create_function("rank", 1, _rank)

    def is_deadlock(self, error):
        return False

{'fraction_non_alphanumeric': 0.07261469180973824, 'fraction_numerical': 0.01350971010413735, 'mean_word_length': 3.2009456264775413, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '908709', 'n_tokens_mistral': 1026, 'n_tokens_neox': 962, 'n_words': 379}