PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Lib/site-packages/django/db/backends/base/features.py

https://gitlab.com/suyesh/Djangotest
Python | 251 lines | 122 code | 54 blank | 75 comment | 1 complexity | d2ce679b023c0275e09ca081c15b6c56 MD5 | raw file
  1. from django.db.models.aggregates import StdDev
  2. from django.db.utils import ProgrammingError
  3. from django.utils.functional import cached_property
  4. class BaseDatabaseFeatures(object):
  5. gis_enabled = False
  6. allows_group_by_pk = False
  7. # True if django.db.backends.utils.typecast_timestamp is used on values
  8. # returned from dates() calls.
  9. needs_datetime_string_cast = True
  10. empty_fetchmany_value = []
  11. update_can_self_select = True
  12. # Does the backend distinguish between '' and None?
  13. interprets_empty_strings_as_nulls = False
  14. # Does the backend allow inserting duplicate NULL rows in a nullable
  15. # unique field? All core backends implement this correctly, but other
  16. # databases such as SQL Server do not.
  17. supports_nullable_unique_constraints = True
  18. # Does the backend allow inserting duplicate rows when a unique_together
  19. # constraint exists and some fields are nullable but not all of them?
  20. supports_partially_nullable_unique_constraints = True
  21. can_use_chunked_reads = True
  22. can_return_id_from_insert = False
  23. has_bulk_insert = False
  24. uses_savepoints = False
  25. can_release_savepoints = False
  26. can_combine_inserts_with_and_without_auto_increment_pk = False
  27. # If True, don't use integer foreign keys referring to, e.g., positive
  28. # integer primary keys.
  29. related_fields_match_type = False
  30. allow_sliced_subqueries = True
  31. has_select_for_update = False
  32. has_select_for_update_nowait = False
  33. supports_select_related = True
  34. # Does the default test database allow multiple connections?
  35. # Usually an indication that the test database is in-memory
  36. test_db_allows_multiple_connections = True
  37. # Can an object be saved without an explicit primary key?
  38. supports_unspecified_pk = False
  39. # Can a fixture contain forward references? i.e., are
  40. # FK constraints checked at the end of transaction, or
  41. # at the end of each save operation?
  42. supports_forward_references = True
  43. # Does the backend truncate names properly when they are too long?
  44. truncates_names = False
  45. # Is there a REAL datatype in addition to floats/doubles?
  46. has_real_datatype = False
  47. supports_subqueries_in_group_by = True
  48. supports_bitwise_or = True
  49. # Is there a true datatype for uuid?
  50. has_native_uuid_field = False
  51. # Is there a true datatype for timedeltas?
  52. has_native_duration_field = False
  53. # Does the database driver support timedeltas as arguments?
  54. # This is only relevant when there is a native duration field.
  55. # Specifically, there is a bug with cx_Oracle:
  56. # https://bitbucket.org/anthony_tuininga/cx_oracle/issue/7/
  57. driver_supports_timedelta_args = False
  58. # Do time/datetime fields have microsecond precision?
  59. supports_microsecond_precision = True
  60. # Does the __regex lookup support backreferencing and grouping?
  61. supports_regex_backreferencing = True
  62. # Can date/datetime lookups be performed using a string?
  63. supports_date_lookup_using_string = True
  64. # Can datetimes with timezones be used?
  65. supports_timezones = True
  66. # Does the database have a copy of the zoneinfo database?
  67. has_zoneinfo_database = True
  68. # When performing a GROUP BY, is an ORDER BY NULL required
  69. # to remove any ordering?
  70. requires_explicit_null_ordering_when_grouping = False
  71. # Does the backend order NULL values as largest or smallest?
  72. nulls_order_largest = False
  73. # Is there a 1000 item limit on query parameters?
  74. supports_1000_query_parameters = True
  75. # Can an object have an autoincrement primary key of 0? MySQL says No.
  76. allows_auto_pk_0 = True
  77. # Do we need to NULL a ForeignKey out, or can the constraint check be
  78. # deferred
  79. can_defer_constraint_checks = False
  80. # date_interval_sql can properly handle mixed Date/DateTime fields and timedeltas
  81. supports_mixed_date_datetime_comparisons = True
  82. # Does the backend support tablespaces? Default to False because it isn't
  83. # in the SQL standard.
  84. supports_tablespaces = False
  85. # Does the backend reset sequences between tests?
  86. supports_sequence_reset = True
  87. # Can the backend determine reliably the length of a CharField?
  88. can_introspect_max_length = True
  89. # Can the backend determine reliably if a field is nullable?
  90. # Note that this is separate from interprets_empty_strings_as_nulls,
  91. # although the latter feature, when true, interferes with correct
  92. # setting (and introspection) of CharFields' nullability.
  93. # This is True for all core backends.
  94. can_introspect_null = True
  95. # Confirm support for introspected foreign keys
  96. # Every database can do this reliably, except MySQL,
  97. # which can't do it for MyISAM tables
  98. can_introspect_foreign_keys = True
  99. # Can the backend introspect an AutoField, instead of an IntegerField?
  100. can_introspect_autofield = False
  101. # Can the backend introspect a BigIntegerField, instead of an IntegerField?
  102. can_introspect_big_integer_field = True
  103. # Can the backend introspect an BinaryField, instead of an TextField?
  104. can_introspect_binary_field = True
  105. # Can the backend introspect an DecimalField, instead of an FloatField?
  106. can_introspect_decimal_field = True
  107. # Can the backend introspect an IPAddressField, instead of an CharField?
  108. can_introspect_ip_address_field = False
  109. # Can the backend introspect a PositiveIntegerField, instead of an IntegerField?
  110. can_introspect_positive_integer_field = False
  111. # Can the backend introspect a SmallIntegerField, instead of an IntegerField?
  112. can_introspect_small_integer_field = False
  113. # Can the backend introspect a TimeField, instead of a DateTimeField?
  114. can_introspect_time_field = True
  115. # Support for the DISTINCT ON clause
  116. can_distinct_on_fields = False
  117. # Does the backend decide to commit before SAVEPOINT statements
  118. # when autocommit is disabled? http://bugs.python.org/issue8145#msg109965
  119. autocommits_when_autocommit_is_off = False
  120. # Does the backend prevent running SQL queries in broken transactions?
  121. atomic_transactions = True
  122. # Can we roll back DDL in a transaction?
  123. can_rollback_ddl = False
  124. # Can we issue more than one ALTER COLUMN clause in an ALTER TABLE?
  125. supports_combined_alters = False
  126. # Does it support foreign keys?
  127. supports_foreign_keys = True
  128. # Does it support CHECK constraints?
  129. supports_column_check_constraints = True
  130. # Does the backend support 'pyformat' style ("... %(name)s ...", {'name': value})
  131. # parameter passing? Note this can be provided by the backend even if not
  132. # supported by the Python driver
  133. supports_paramstyle_pyformat = True
  134. # Does the backend require literal defaults, rather than parameterized ones?
  135. requires_literal_defaults = False
  136. # Does the backend require a connection reset after each material schema change?
  137. connection_persists_old_columns = False
  138. # What kind of error does the backend throw when accessing closed cursor?
  139. closed_cursor_error_class = ProgrammingError
  140. # Does 'a' LIKE 'A' match?
  141. has_case_insensitive_like = True
  142. # Does the backend require the sqlparse library for splitting multi-line
  143. # statements before executing them?
  144. requires_sqlparse_for_splitting = True
  145. # Suffix for backends that don't support "SELECT xxx;" queries.
  146. bare_select_suffix = ''
  147. # If NULL is implied on columns without needing to be explicitly specified
  148. implied_column_null = False
  149. uppercases_column_names = False
  150. # Does the backend support "select for update" queries with limit (and offset)?
  151. supports_select_for_update_with_limit = True
  152. def __init__(self, connection):
  153. self.connection = connection
  154. @cached_property
  155. def supports_transactions(self):
  156. """Confirm support for transactions."""
  157. with self.connection.cursor() as cursor:
  158. cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)')
  159. self.connection.set_autocommit(False)
  160. cursor.execute('INSERT INTO ROLLBACK_TEST (X) VALUES (8)')
  161. self.connection.rollback()
  162. self.connection.set_autocommit(True)
  163. cursor.execute('SELECT COUNT(X) FROM ROLLBACK_TEST')
  164. count, = cursor.fetchone()
  165. cursor.execute('DROP TABLE ROLLBACK_TEST')
  166. return count == 0
  167. @cached_property
  168. def supports_stddev(self):
  169. """Confirm support for STDDEV and related stats functions."""
  170. try:
  171. self.connection.ops.check_expression_support(StdDev(1))
  172. return True
  173. except NotImplementedError:
  174. return False
  175. def introspected_boolean_field_type(self, field=None, created_separately=False):
  176. """
  177. What is the type returned when the backend introspects a BooleanField?
  178. The optional arguments may be used to give further details of the field to be
  179. introspected; in particular, they are provided by Django's test suite:
  180. field -- the field definition
  181. created_separately -- True if the field was added via a SchemaEditor's AddField,
  182. False if the field was created with the model
  183. Note that return value from this function is compared by tests against actual
  184. introspection results; it should provide expectations, not run an introspection
  185. itself.
  186. """
  187. if self.can_introspect_null and field and field.null:
  188. return 'NullBooleanField'
  189. return 'BooleanField'