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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. from __future__ import unicode_literals
  2. from django.db import utils
  3. from django.db.backends.base.features import BaseDatabaseFeatures
  4. from django.utils import six
  5. from django.utils.functional import cached_property
  6. from .base import Database
  7. try:
  8. import pytz
  9. except ImportError:
  10. pytz = None
  11. class DatabaseFeatures(BaseDatabaseFeatures):
  12. # SQLite cannot handle us only partially reading from a cursor's result set
  13. # and then writing the same rows to the database in another cursor. This
  14. # setting ensures we always read result sets fully into memory all in one
  15. # go.
  16. can_use_chunked_reads = False
  17. test_db_allows_multiple_connections = False
  18. supports_unspecified_pk = True
  19. supports_timezones = False
  20. supports_1000_query_parameters = False
  21. supports_mixed_date_datetime_comparisons = False
  22. has_bulk_insert = True
  23. can_combine_inserts_with_and_without_auto_increment_pk = False
  24. supports_foreign_keys = False
  25. supports_column_check_constraints = False
  26. autocommits_when_autocommit_is_off = True
  27. can_introspect_decimal_field = False
  28. can_introspect_positive_integer_field = True
  29. can_introspect_small_integer_field = True
  30. supports_transactions = True
  31. atomic_transactions = False
  32. can_rollback_ddl = True
  33. supports_paramstyle_pyformat = False
  34. supports_sequence_reset = False
  35. can_clone_databases = True
  36. @cached_property
  37. def uses_savepoints(self):
  38. return Database.sqlite_version_info >= (3, 6, 8)
  39. @cached_property
  40. def can_release_savepoints(self):
  41. return self.uses_savepoints
  42. @cached_property
  43. def can_share_in_memory_db(self):
  44. return (
  45. six.PY3 and
  46. Database.__name__ == 'sqlite3.dbapi2' and
  47. Database.sqlite_version_info >= (3, 7, 13)
  48. )
  49. @cached_property
  50. def supports_stddev(self):
  51. """Confirm support for STDDEV and related stats functions
  52. SQLite supports STDDEV as an extension package; so
  53. connection.ops.check_expression_support() can't unilaterally
  54. rule out support for STDDEV. We need to manually check
  55. whether the call works.
  56. """
  57. with self.connection.cursor() as cursor:
  58. cursor.execute('CREATE TABLE STDDEV_TEST (X INT)')
  59. try:
  60. cursor.execute('SELECT STDDEV(*) FROM STDDEV_TEST')
  61. has_support = True
  62. except utils.DatabaseError:
  63. has_support = False
  64. cursor.execute('DROP TABLE STDDEV_TEST')
  65. return has_support
  66. @cached_property
  67. def has_zoneinfo_database(self):
  68. return pytz is not None