1from__future__importannotations 2 3fromfunctoolsimportcached_property 4fromtypingimportTYPE_CHECKING,Any 5 6ifTYPE_CHECKING: 7fromplain.models.backends.base.baseimportBaseDatabaseWrapper 8 9 10classBaseDatabaseFeatures: 11# An optional tuple indicating the minimum supported database version. 12minimum_database_version=None 13allows_group_by_selected_pks=False 14allows_group_by_select_index=True 15empty_fetchmany_value=[] 16update_can_self_select=True 17 18# Does the backend support initially deferrable unique constraints? 19supports_deferrable_unique_constraints=False 20 21can_use_chunked_reads=True 22can_return_columns_from_insert=False 23can_return_rows_from_bulk_insert=False 24has_bulk_insert=True 25uses_savepoints=True 26 27# If True, don't use integer foreign keys referring to, e.g., positive 28# integer primary keys. 29related_fields_match_type=False 30has_select_for_update=False 31has_select_for_update_nowait=False 32has_select_for_update_skip_locked=False 33has_select_for_update_of=False 34has_select_for_no_key_update=False 35# Does the database's SELECT FOR UPDATE OF syntax require a column rather 36# than a table? 37select_for_update_of_column=False 38 39# Does the backend truncate names properly when they are too long? 40truncates_names=False 41 42# Does the backend ignore unnecessary ORDER BY clauses in subqueries? 43ignores_unnecessary_order_by_in_subqueries=True 44 45# Is there a true datatype for uuid? 46has_native_uuid_field=False 47 48# Is there a true datatype for timedeltas? 49has_native_duration_field=False 50 51# Does the database driver supports same type temporal data subtraction 52# by returning the type used to store duration field? 53supports_temporal_subtraction=False 54 55# Does the database have a copy of the zoneinfo database? 56has_zoneinfo_database=True 57 58# Does the backend support NULLS FIRST and NULLS LAST in ORDER BY? 59supports_order_by_nulls_modifier=True 60 61# Does the backend orders NULLS FIRST by default? 62order_by_nulls_first=False 63 64# The database's limit on the number of query parameters. 65max_query_params=None 66 67# Can an object have an autoincrement primary key of 0? 68allows_auto_pk_0=True 69 70# Do we need to NULL a ForeignKey out, or can the constraint check be 71# deferred 72can_defer_constraint_checks=False 73 74# Can the backend introspect the column order (ASC/DESC) for indexes? 75supports_index_column_ordering=True 76 77# Can we roll back DDL in a transaction? 78can_rollback_ddl=False 79 80# Does it support operations requiring references rename in a transaction? 81supports_atomic_references_rename=True 82 83# Can we issue more than one ALTER COLUMN clause in an ALTER TABLE? 84supports_combined_alters=False 85 86# Does it support foreign keys? 87supports_foreign_keys=True 88 89# Can an index be renamed? 90can_rename_index=False 91 92# Does it support CHECK constraints? 93supports_column_check_constraints=True 94supports_table_check_constraints=True 95# Does the backend support introspection of CHECK constraints? 96can_introspect_check_constraints=True 97 98# Does the backend require literal defaults, rather than parameterized ones? 99requires_literal_defaults=False100101# Does the backend require a connection reset after each material schema change?102connection_persists_old_columns=False103104# Suffix for backends that don't support "SELECT xxx;" queries.105bare_select_suffix=""106107# If NULL is implied on columns without needing to be explicitly specified108implied_column_null=False109110# Does the backend support "select for update" queries with limit (and offset)?111supports_select_for_update_with_limit=True112113# Does the backend consider table names with different casing to114# be equal?115ignores_table_name_case=False116117# Place FOR UPDATE right after FROM clause. Used on MSSQL.118for_update_after_from=False119120# Combinatorial flags121supports_select_union=True122supports_select_intersection=True123supports_select_difference=True124supports_slicing_ordering_in_compound=False125supports_parentheses_in_compound=True126requires_compound_order_by_subquery=False127128# Does the database support SQL 2003 FILTER (WHERE ...) in aggregate129# expressions?130supports_aggregate_filter_clause=False131132# Does the backend support window expressions (expression OVER (...))?133supports_over_clause=False134only_supports_unbounded_with_preceding_and_following=False135136# Does the backend support keyword parameters for cursor.callproc()?137supports_callproc_kwargs=False138139# What formats does the backend EXPLAIN syntax support?140supported_explain_formats=set()141142# Does the backend support updating rows on constraint or uniqueness errors143# during INSERT?144supports_update_conflicts=False145supports_update_conflicts_with_target=False146147# Does this backend require casting the results of CASE expressions used148# in UPDATE statements to ensure the expression has the correct type?149requires_casted_case_in_updates=False150151# Does the backend support partial indexes (CREATE INDEX ... WHERE ...)?152supports_partial_indexes=True153# Does the backend support covering indexes (CREATE INDEX ... INCLUDE ...)?154supports_covering_indexes=False155# Does the backend support indexes on expressions?156supports_expression_indexes=True157# Does the backend treat COLLATE as an indexed expression?158collate_as_index_expression=False159160# Does the backend support boolean expressions in SELECT and GROUP BY161# clauses?162supports_boolean_expr_in_select_clause=True163# Does the backend support comparing boolean expressions in WHERE clauses?164# Eg: WHERE (price > 0) IS NOT NULL165supports_comparing_boolean_expr=True166167# Does the backend support JSONField?168supports_json_field=True169# Can the backend introspect a JSONField?170can_introspect_json_field=True171# Is there a true datatype for JSON?172has_native_json_field=False173# Does the backend support __contains and __contained_by lookups for174# a JSONField?175supports_json_field_contains=True176# Does the backend support JSONObject() database function?177has_json_object_function=True178179# Does the backend support column collations?180supports_collation_on_charfield=True181supports_collation_on_textfield=True182183# Does the backend support column and table comments?184supports_comments=False185# Does the backend support column comments in ADD COLUMN statements?186supports_comments_inline=False187188# Does the backend support the logical XOR operator?189supports_logical_xor=False190191# Does the backend support unlimited character columns?192supports_unlimited_charfield=False193194def__init__(self,connection:BaseDatabaseWrapper):195self.connection=connection196197@cached_property198defsupports_explaining_query_execution(self)->bool:199"""Does this backend support explaining query execution?"""200returnself.connection.ops.explain_prefixisnotNone201202@cached_property203defsupports_transactions(self)->bool:204"""Confirm support for transactions."""205withself.connection.cursor()ascursor:206cursor.execute("CREATE TABLE ROLLBACK_TEST (X INT)")207self.connection.set_autocommit(False)208cursor.execute("INSERT INTO ROLLBACK_TEST (X) VALUES (8)")209self.connection.rollback()210self.connection.set_autocommit(True)211cursor.execute("SELECT COUNT(X) FROM ROLLBACK_TEST")212(count,)=cursor.fetchone()213cursor.execute("DROP TABLE ROLLBACK_TEST")214returncount==0215216defallows_group_by_selected_pks_on_model(self,model:Any)->bool:217ifnotself.allows_group_by_selected_pks:218returnFalse219returnTrue