1fromfunctoolsimportcached_property 2 3 4classBaseDatabaseFeatures: 5# An optional tuple indicating the minimum supported database version. 6minimum_database_version=None 7allows_group_by_selected_pks=False 8allows_group_by_select_index=True 9empty_fetchmany_value=[] 10update_can_self_select=True 11 12# Does the backend support initially deferrable unique constraints? 13supports_deferrable_unique_constraints=False 14 15can_use_chunked_reads=True 16can_return_columns_from_insert=False 17can_return_rows_from_bulk_insert=False 18has_bulk_insert=True 19uses_savepoints=True 20 21# If True, don't use integer foreign keys referring to, e.g., positive 22# integer primary keys. 23related_fields_match_type=False 24has_select_for_update=False 25has_select_for_update_nowait=False 26has_select_for_update_skip_locked=False 27has_select_for_update_of=False 28has_select_for_no_key_update=False 29# Does the database's SELECT FOR UPDATE OF syntax require a column rather 30# than a table? 31select_for_update_of_column=False 32 33# Does the backend truncate names properly when they are too long? 34truncates_names=False 35 36# Does the backend ignore unnecessary ORDER BY clauses in subqueries? 37ignores_unnecessary_order_by_in_subqueries=True 38 39# Is there a true datatype for uuid? 40has_native_uuid_field=False 41 42# Is there a true datatype for timedeltas? 43has_native_duration_field=False 44 45# Does the database driver supports same type temporal data subtraction 46# by returning the type used to store duration field? 47supports_temporal_subtraction=False 48 49# Does the database have a copy of the zoneinfo database? 50has_zoneinfo_database=True 51 52# Does the backend support NULLS FIRST and NULLS LAST in ORDER BY? 53supports_order_by_nulls_modifier=True 54 55# Does the backend orders NULLS FIRST by default? 56order_by_nulls_first=False 57 58# The database's limit on the number of query parameters. 59max_query_params=None 60 61# Can an object have an autoincrement primary key of 0? 62allows_auto_pk_0=True 63 64# Do we need to NULL a ForeignKey out, or can the constraint check be 65# deferred 66can_defer_constraint_checks=False 67 68# Can the backend introspect the column order (ASC/DESC) for indexes? 69supports_index_column_ordering=True 70 71# Can we roll back DDL in a transaction? 72can_rollback_ddl=False 73 74# Does it support operations requiring references rename in a transaction? 75supports_atomic_references_rename=True 76 77# Can we issue more than one ALTER COLUMN clause in an ALTER TABLE? 78supports_combined_alters=False 79 80# Does it support foreign keys? 81supports_foreign_keys=True 82 83# Can an index be renamed? 84can_rename_index=False 85 86# Does it support CHECK constraints? 87supports_column_check_constraints=True 88supports_table_check_constraints=True 89# Does the backend support introspection of CHECK constraints? 90can_introspect_check_constraints=True 91 92# Does the backend require literal defaults, rather than parameterized ones? 93requires_literal_defaults=False 94 95# Does the backend require a connection reset after each material schema change? 96connection_persists_old_columns=False 97 98# Suffix for backends that don't support "SELECT xxx;" queries. 99bare_select_suffix=""100101# If NULL is implied on columns without needing to be explicitly specified102implied_column_null=False103104# Does the backend support "select for update" queries with limit (and offset)?105supports_select_for_update_with_limit=True106107# Does the backend consider table names with different casing to108# be equal?109ignores_table_name_case=False110111# Place FOR UPDATE right after FROM clause. Used on MSSQL.112for_update_after_from=False113114# Combinatorial flags115supports_select_union=True116supports_select_intersection=True117supports_select_difference=True118supports_slicing_ordering_in_compound=False119supports_parentheses_in_compound=True120requires_compound_order_by_subquery=False121122# Does the database support SQL 2003 FILTER (WHERE ...) in aggregate123# expressions?124supports_aggregate_filter_clause=False125126# Does the backend support window expressions (expression OVER (...))?127supports_over_clause=False128only_supports_unbounded_with_preceding_and_following=False129130# Does the backend support keyword parameters for cursor.callproc()?131supports_callproc_kwargs=False132133# What formats does the backend EXPLAIN syntax support?134supported_explain_formats=set()135136# Does the backend support updating rows on constraint or uniqueness errors137# during INSERT?138supports_update_conflicts=False139supports_update_conflicts_with_target=False140141# Does this backend require casting the results of CASE expressions used142# in UPDATE statements to ensure the expression has the correct type?143requires_casted_case_in_updates=False144145# Does the backend support partial indexes (CREATE INDEX ... WHERE ...)?146supports_partial_indexes=True147# Does the backend support covering indexes (CREATE INDEX ... INCLUDE ...)?148supports_covering_indexes=False149# Does the backend support indexes on expressions?150supports_expression_indexes=True151# Does the backend treat COLLATE as an indexed expression?152collate_as_index_expression=False153154# Does the backend support boolean expressions in SELECT and GROUP BY155# clauses?156supports_boolean_expr_in_select_clause=True157# Does the backend support comparing boolean expressions in WHERE clauses?158# Eg: WHERE (price > 0) IS NOT NULL159supports_comparing_boolean_expr=True160161# Does the backend support JSONField?162supports_json_field=True163# Can the backend introspect a JSONField?164can_introspect_json_field=True165# Is there a true datatype for JSON?166has_native_json_field=False167# Does the backend support __contains and __contained_by lookups for168# a JSONField?169supports_json_field_contains=True170# Does the backend support JSONObject() database function?171has_json_object_function=True172173# Does the backend support column collations?174supports_collation_on_charfield=True175supports_collation_on_textfield=True176177# Does the backend support column and table comments?178supports_comments=False179# Does the backend support column comments in ADD COLUMN statements?180supports_comments_inline=False181182# Does the backend support the logical XOR operator?183supports_logical_xor=False184185# Does the backend support unlimited character columns?186supports_unlimited_charfield=False187188def__init__(self,connection):189self.connection=connection190191@cached_property192defsupports_explaining_query_execution(self):193"""Does this backend support explaining query execution?"""194returnself.connection.ops.explain_prefixisnotNone195196@cached_property197defsupports_transactions(self):198"""Confirm support for transactions."""199withself.connection.cursor()ascursor:200cursor.execute("CREATE TABLE ROLLBACK_TEST (X INT)")201self.connection.set_autocommit(False)202cursor.execute("INSERT INTO ROLLBACK_TEST (X) VALUES (8)")203self.connection.rollback()204self.connection.set_autocommit(True)205cursor.execute("SELECT COUNT(X) FROM ROLLBACK_TEST")206(count,)=cursor.fetchone()207cursor.execute("DROP TABLE ROLLBACK_TEST")208returncount==0209210defallows_group_by_selected_pks_on_model(self,model):211ifnotself.allows_group_by_selected_pks:212returnFalse213returnTrue