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
|
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
|
|
|
|
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-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
|
2020-03-18 10:00:28 +08:00
|
|
|
order_by_nulls_first = True
|
2020-08-08 19:37:06 +08:00
|
|
|
test_collations = {
|
|
|
|
'ci': 'utf8_general_ci',
|
2020-07-18 19:17:39 +08:00
|
|
|
'non_default': 'utf8_esperanto_ci',
|
2020-09-18 18:12:27 +08:00
|
|
|
'swedish_ci': 'utf8_swedish_ci',
|
2020-08-08 19:37:06 +08:00
|
|
|
}
|
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"
|
2020-06-21 01:17:22 +08:00
|
|
|
return self.connection.mysql_server_data['default_storage_engine']
|
2015-01-13 04:20:40 +08:00
|
|
|
|
2020-07-20 15:48:31 +08:00
|
|
|
@cached_property
|
|
|
|
def allows_auto_pk_0(self):
|
|
|
|
"""
|
|
|
|
Autoincrement primary key can be set to 0 if it doesn't generate new
|
|
|
|
autoincrement values.
|
|
|
|
"""
|
|
|
|
return 'NO_AUTO_VALUE_ON_ZERO' in self.connection.sql_mode
|
|
|
|
|
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'
|
|
|
|
|
2020-05-27 06:25:45 +08:00
|
|
|
@cached_property
|
|
|
|
def introspected_field_types(self):
|
|
|
|
return {
|
|
|
|
**super().introspected_field_types,
|
|
|
|
'BinaryField': 'TextField',
|
|
|
|
'BooleanField': 'IntegerField',
|
|
|
|
'DurationField': 'BigIntegerField',
|
|
|
|
'GenericIPAddressField': 'CharField',
|
|
|
|
}
|
|
|
|
|
2020-03-25 16:58:21 +08:00
|
|
|
@cached_property
|
|
|
|
def can_return_columns_from_insert(self):
|
|
|
|
return self.connection.mysql_is_mariadb and self.connection.mysql_version >= (10, 5, 0)
|
|
|
|
|
|
|
|
can_return_rows_from_bulk_insert = property(operator.attrgetter('can_return_columns_from_insert'))
|
|
|
|
|
2015-01-13 04:20:40 +08:00
|
|
|
@cached_property
|
|
|
|
def has_zoneinfo_database(self):
|
2020-06-21 01:17:22 +08:00
|
|
|
return self.connection.mysql_server_data['has_zoneinfo_database']
|
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):
|
2020-06-21 01:17:22 +08:00
|
|
|
return self.connection.mysql_server_data['sql_auto_is_null']
|
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
|
|
|
|
2019-11-05 17:18:47 +08:00
|
|
|
@cached_property
|
|
|
|
def has_select_for_update_nowait(self):
|
|
|
|
if self.connection.mysql_is_mariadb:
|
|
|
|
return self.connection.mysql_version >= (10, 3, 0)
|
|
|
|
return self.connection.mysql_version >= (8, 0, 1)
|
2018-05-19 07:37:36 +08:00
|
|
|
|
2020-07-12 12:25:03 +08:00
|
|
|
@cached_property
|
|
|
|
def has_select_for_update_of(self):
|
|
|
|
return not self.connection.mysql_is_mariadb and self.connection.mysql_version >= (8, 0, 1)
|
|
|
|
|
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):
|
2020-06-21 01:17:22 +08:00
|
|
|
return self.connection.mysql_server_data['lower_case_table_names']
|
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
|
2019-06-09 08:56:37 +08:00
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def supports_json_field(self):
|
|
|
|
if self.connection.mysql_is_mariadb:
|
|
|
|
return self.connection.mysql_version >= (10, 2, 7)
|
|
|
|
return self.connection.mysql_version >= (5, 7, 8)
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def can_introspect_json_field(self):
|
|
|
|
if self.connection.mysql_is_mariadb:
|
|
|
|
return self.supports_json_field and self.can_introspect_check_constraints
|
|
|
|
return self.supports_json_field
|