You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

features.py 2.6 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from django.db.backends.base.features import BaseDatabaseFeatures
  2. from django.utils.functional import cached_property
  3. from .base import Database
  4. try:
  5. import pytz
  6. except ImportError:
  7. pytz = None
  8. class DatabaseFeatures(BaseDatabaseFeatures):
  9. empty_fetchmany_value = ()
  10. update_can_self_select = False
  11. allows_group_by_pk = True
  12. related_fields_match_type = True
  13. allow_sliced_subqueries = False
  14. has_bulk_insert = True
  15. has_select_for_update = True
  16. has_select_for_update_nowait = False
  17. supports_forward_references = False
  18. supports_regex_backreferencing = False
  19. supports_date_lookup_using_string = False
  20. can_introspect_autofield = True
  21. can_introspect_binary_field = False
  22. can_introspect_small_integer_field = True
  23. supports_timezones = False
  24. requires_explicit_null_ordering_when_grouping = True
  25. allows_auto_pk_0 = False
  26. uses_savepoints = True
  27. can_release_savepoints = True
  28. atomic_transactions = False
  29. supports_column_check_constraints = False
  30. can_clone_databases = True
  31. @cached_property
  32. def _mysql_storage_engine(self):
  33. "Internal method used in Django tests. Don't rely on this from your code"
  34. with self.connection.cursor() as cursor:
  35. cursor.execute("SELECT ENGINE FROM INFORMATION_SCHEMA.ENGINES WHERE SUPPORT = 'DEFAULT'")
  36. result = cursor.fetchone()
  37. return result[0]
  38. @cached_property
  39. def can_introspect_foreign_keys(self):
  40. "Confirm support for introspected foreign keys"
  41. return self._mysql_storage_engine != 'MyISAM'
  42. @cached_property
  43. def supports_microsecond_precision(self):
  44. # See https://github.com/farcepest/MySQLdb1/issues/24 for the reason
  45. # about requiring MySQLdb 1.2.5
  46. return self.connection.mysql_version >= (5, 6, 4) and Database.version_info >= (1, 2, 5)
  47. @cached_property
  48. def has_zoneinfo_database(self):
  49. # MySQL accepts full time zones names (eg. Africa/Nairobi) but rejects
  50. # abbreviations (eg. EAT). When pytz isn't installed and the current
  51. # time zone is LocalTimezone (the only sensible value in this
  52. # context), the current time zone name will be an abbreviation. As a
  53. # consequence, MySQL cannot perform time zone conversions reliably.
  54. if pytz is None:
  55. return False
  56. # Test if the time zone definitions are installed.
  57. with self.connection.cursor() as cursor:
  58. cursor.execute("SELECT 1 FROM mysql.time_zone LIMIT 1")
  59. return cursor.fetchone() is not None
  60. def introspected_boolean_field_type(self, *args, **kwargs):
  61. return 'IntegerField'