2018-11-16 23:25:26 +08:00
|
|
|
import operator
|
|
|
|
|
2015-01-13 04:20:40 +08:00
|
|
|
from django.db.backends.base.features import BaseDatabaseFeatures
|
|
|
|
from django.utils.functional import cached_property
|
|
|
|
|
|
|
|
|
|
|
|
class DatabaseFeatures(BaseDatabaseFeatures):
|
|
|
|
empty_fetchmany_value = ()
|
|
|
|
allows_group_by_pk = True
|
|
|
|
related_fields_match_type = True
|
2018-02-07 15:27:47 +08:00
|
|
|
# MySQL doesn't support sliced subqueries with IN/ALL/ANY/SOME.
|
|
|
|
allow_sliced_subqueries_with_in = False
|
2015-01-13 04:20:40 +08:00
|
|
|
has_select_for_update = True
|
|
|
|
supports_forward_references = False
|
|
|
|
supports_regex_backreferencing = False
|
|
|
|
supports_date_lookup_using_string = False
|
|
|
|
can_introspect_autofield = True
|
|
|
|
can_introspect_binary_field = False
|
2018-10-21 15:08:05 +08:00
|
|
|
can_introspect_duration_field = False
|
2015-01-13 04:20:40 +08:00
|
|
|
can_introspect_small_integer_field = True
|
2017-03-08 23:56:00 +08:00
|
|
|
can_introspect_positive_integer_field = True
|
2018-03-16 22:52:04 +08:00
|
|
|
introspected_boolean_field_type = 'IntegerField'
|
2016-07-26 09:04:28 +08:00
|
|
|
supports_index_column_ordering = False
|
2015-01-13 04:20:40 +08:00
|
|
|
supports_timezones = False
|
|
|
|
requires_explicit_null_ordering_when_grouping = True
|
|
|
|
allows_auto_pk_0 = False
|
|
|
|
can_release_savepoints = True
|
|
|
|
atomic_transactions = False
|
2015-09-06 17:12:08 +08:00
|
|
|
can_clone_databases = True
|
2016-01-20 09:43:41 +08:00
|
|
|
supports_temporal_subtraction = True
|
2017-01-14 21:32:07 +08:00
|
|
|
supports_select_intersection = False
|
|
|
|
supports_select_difference = False
|
|
|
|
supports_slicing_ordering_in_compound = True
|
2017-05-23 23:02:40 +08:00
|
|
|
supports_index_on_text_field = False
|
2017-07-25 03:51:29 +08:00
|
|
|
has_case_insensitive_like = False
|
2017-08-09 04:13:02 +08:00
|
|
|
create_test_procedure_without_params_sql = """
|
|
|
|
CREATE PROCEDURE test_procedure ()
|
|
|
|
BEGIN
|
|
|
|
DECLARE V_I INTEGER;
|
|
|
|
SET V_I = 1;
|
|
|
|
END;
|
|
|
|
"""
|
|
|
|
create_test_procedure_with_int_param_sql = """
|
|
|
|
CREATE PROCEDURE test_procedure (P_I INTEGER)
|
|
|
|
BEGIN
|
|
|
|
DECLARE V_I INTEGER;
|
|
|
|
SET V_I = P_I;
|
|
|
|
END;
|
|
|
|
"""
|
2018-04-04 00:24:04 +08:00
|
|
|
db_functions_convert_bytes_to_str = True
|
2018-09-13 15:34:02 +08:00
|
|
|
# Neither MySQL nor MariaDB support partial indexes.
|
|
|
|
supports_partial_indexes = False
|
2019-11-04 21:47:58 +08:00
|
|
|
supports_order_by_nulls_modifier = False
|
2015-01-13 04:20:40 +08:00
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def _mysql_storage_engine(self):
|
|
|
|
"Internal method used in Django tests. Don't rely on this from your code"
|
|
|
|
with self.connection.cursor() as cursor:
|
|
|
|
cursor.execute("SELECT ENGINE FROM INFORMATION_SCHEMA.ENGINES WHERE SUPPORT = 'DEFAULT'")
|
|
|
|
result = cursor.fetchone()
|
|
|
|
return result[0]
|
|
|
|
|
2019-10-24 18:18:13 +08:00
|
|
|
@cached_property
|
|
|
|
def update_can_self_select(self):
|
|
|
|
return self.connection.mysql_is_mariadb and self.connection.mysql_version >= (10, 3, 2)
|
|
|
|
|
2015-01-13 04:20:40 +08:00
|
|
|
@cached_property
|
|
|
|
def can_introspect_foreign_keys(self):
|
|
|
|
"Confirm support for introspected foreign keys"
|
|
|
|
return self._mysql_storage_engine != 'MyISAM'
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def has_zoneinfo_database(self):
|
2019-09-20 10:23:33 +08:00
|
|
|
# Test if the time zone definitions are installed. CONVERT_TZ returns
|
|
|
|
# NULL if 'UTC' timezone isn't loaded into the mysql.time_zone.
|
2015-01-13 04:20:40 +08:00
|
|
|
with self.connection.cursor() as cursor:
|
2019-09-20 10:23:33 +08:00
|
|
|
cursor.execute("SELECT CONVERT_TZ('2001-01-01 01:00:00', 'UTC', 'UTC')")
|
|
|
|
return cursor.fetchone()[0] is not None
|
2015-01-13 04:20:40 +08:00
|
|
|
|
2015-12-15 10:19:40 +08:00
|
|
|
@cached_property
|
|
|
|
def is_sql_auto_is_null_enabled(self):
|
|
|
|
with self.connection.cursor() as cursor:
|
|
|
|
cursor.execute('SELECT @@SQL_AUTO_IS_NULL')
|
2016-08-02 22:52:31 +08:00
|
|
|
result = cursor.fetchone()
|
|
|
|
return result and result[0] == 1
|
2016-09-30 03:05:35 +08:00
|
|
|
|
2017-09-18 21:42:29 +08:00
|
|
|
@cached_property
|
|
|
|
def supports_over_clause(self):
|
2018-07-10 02:59:42 +08:00
|
|
|
if self.connection.mysql_is_mariadb:
|
2019-10-16 18:58:05 +08:00
|
|
|
return True
|
2017-09-18 21:42:29 +08:00
|
|
|
return self.connection.mysql_version >= (8, 0, 2)
|
|
|
|
|
2019-10-09 19:07:50 +08:00
|
|
|
supports_frame_range_fixed_distance = property(operator.attrgetter('supports_over_clause'))
|
|
|
|
|
2019-07-14 07:24:35 +08:00
|
|
|
@cached_property
|
|
|
|
def supports_column_check_constraints(self):
|
2019-09-04 22:54:27 +08:00
|
|
|
if self.connection.mysql_is_mariadb:
|
|
|
|
return self.connection.mysql_version >= (10, 2, 1)
|
|
|
|
return self.connection.mysql_version >= (8, 0, 16)
|
2019-07-14 07:24:35 +08:00
|
|
|
|
|
|
|
supports_table_check_constraints = property(operator.attrgetter('supports_column_check_constraints'))
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def can_introspect_check_constraints(self):
|
|
|
|
if self.connection.mysql_is_mariadb:
|
|
|
|
version = self.connection.mysql_version
|
2019-09-06 17:53:54 +08:00
|
|
|
return (version >= (10, 2, 22) and version < (10, 3)) or version >= (10, 3, 10)
|
2019-09-04 22:54:27 +08:00
|
|
|
return self.connection.mysql_version >= (8, 0, 16)
|
2019-07-14 07:24:35 +08:00
|
|
|
|
2018-05-19 07:37:36 +08:00
|
|
|
@cached_property
|
|
|
|
def has_select_for_update_skip_locked(self):
|
2018-07-10 02:59:42 +08:00
|
|
|
return not self.connection.mysql_is_mariadb and self.connection.mysql_version >= (8, 0, 1)
|
2018-05-19 07:37:36 +08:00
|
|
|
|
2018-11-16 23:25:26 +08:00
|
|
|
has_select_for_update_nowait = property(operator.attrgetter('has_select_for_update_skip_locked'))
|
2018-05-19 07:37:36 +08:00
|
|
|
|
2017-09-10 22:34:18 +08:00
|
|
|
@cached_property
|
|
|
|
def needs_explain_extended(self):
|
2018-07-10 02:59:42 +08:00
|
|
|
# EXTENDED is deprecated (and not required) in MySQL 5.7.
|
|
|
|
return not self.connection.mysql_is_mariadb and self.connection.mysql_version < (5, 7)
|
2017-09-10 22:34:18 +08:00
|
|
|
|
2019-10-22 00:34:19 +08:00
|
|
|
@cached_property
|
|
|
|
def supports_explain_analyze(self):
|
|
|
|
return self.connection.mysql_is_mariadb or self.connection.mysql_version >= (8, 0, 18)
|
|
|
|
|
2019-10-22 00:32:56 +08:00
|
|
|
@cached_property
|
|
|
|
def supported_explain_formats(self):
|
|
|
|
# Alias MySQL's TRADITIONAL to TEXT for consistency with other
|
|
|
|
# backends.
|
|
|
|
formats = {'JSON', 'TEXT', 'TRADITIONAL'}
|
|
|
|
if not self.connection.mysql_is_mariadb and self.connection.mysql_version >= (8, 0, 16):
|
|
|
|
formats.add('TREE')
|
|
|
|
return formats
|
|
|
|
|
2016-09-30 03:05:35 +08:00
|
|
|
@cached_property
|
|
|
|
def supports_transactions(self):
|
|
|
|
"""
|
|
|
|
All storage engines except MyISAM support transactions.
|
|
|
|
"""
|
|
|
|
return self._mysql_storage_engine != 'MyISAM'
|
2016-11-29 02:29:21 +08:00
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def ignores_table_name_case(self):
|
|
|
|
with self.connection.cursor() as cursor:
|
|
|
|
cursor.execute('SELECT @@LOWER_CASE_TABLE_NAMES')
|
|
|
|
result = cursor.fetchone()
|
|
|
|
return result and result[0] != 0
|
2018-07-26 07:45:32 +08:00
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def supports_default_in_lead_lag(self):
|
|
|
|
# To be added in https://jira.mariadb.org/browse/MDEV-12981.
|
|
|
|
return not self.connection.mysql_is_mariadb
|