Debian Codegraph @

django/db/backends/oracle/features.py

raw
1 from django.db import DatabaseError, InterfaceError
2 from django.db.backends.base.features import BaseDatabaseFeatures
3 from django.db.backends.oracle.oracledb_any import is_oracledb
4 from django.utils.functional import cached_property
5
6
7 class DatabaseFeatures(BaseDatabaseFeatures):
8 minimum_database_version = (19,)
9 # Oracle crashes with "ORA-00932: inconsistent datatypes: expected - got
10 # BLOB" when grouping by LOBs (#24096).
11 allows_group_by_lob = False
12 # Although GROUP BY select index is supported by Oracle 23c+, it requires
13 # GROUP_BY_POSITION_ENABLED to be enabled to avoid backward compatibility
14 # issues. Introspection of this settings is not straightforward.
15 allows_group_by_select_index = False
16 interprets_empty_strings_as_nulls = True
17 has_select_for_update = True
18 has_select_for_update_nowait = True
19 has_select_for_update_skip_locked = True
20 has_select_for_update_of = True
21 select_for_update_of_column = True
22 can_return_columns_from_insert = True
23 supports_subqueries_in_group_by = False
24 ignores_unnecessary_order_by_in_subqueries = False
25 supports_transactions = True
26 supports_timezones = False
27 has_native_duration_field = True
28 can_defer_constraint_checks = True
29 supports_partially_nullable_unique_constraints = False
30 supports_deferrable_unique_constraints = True
31 truncates_names = True
32 supports_comments = True
33 supports_tablespaces = True
34 supports_sequence_reset = False
35 can_introspect_materialized_views = True
36 atomic_transactions = False
37 nulls_order_largest = True
38 requires_literal_defaults = True
39 supports_default_keyword_in_bulk_insert = False
40 closed_cursor_error_class = InterfaceError
41 # Select for update with limit can be achieved on Oracle, but not with the
42 # current backend.
43 supports_select_for_update_with_limit = False
44 supports_temporal_subtraction = True
45 # Oracle doesn't ignore quoted identifiers case but the current backend
46 # does by uppercasing all identifiers.
47 ignores_table_name_case = True
48 supports_index_on_text_field = False
49 create_test_procedure_without_params_sql = """
50 CREATE PROCEDURE "TEST_PROCEDURE" AS
51 V_I INTEGER;
52 BEGIN
53 V_I := 1;
54 END;
55 """
56 create_test_procedure_with_int_param_sql = """
57 CREATE PROCEDURE "TEST_PROCEDURE" (P_I INTEGER) AS
58 V_I INTEGER;
59 BEGIN
60 V_I := P_I;
61 END;
62 """
63 supports_callproc_kwargs = True
64 supports_over_clause = True
65 supports_frame_range_fixed_distance = True
66 supports_ignore_conflicts = False
67 max_query_params = 2**16 - 1
68 supports_partial_indexes = False
69 supports_stored_generated_columns = False
70 supports_virtual_generated_columns = True
71 can_rename_index = True
72 supports_slicing_ordering_in_compound = True
73 requires_compound_order_by_subquery = True
74 allows_multiple_constraints_on_same_fields = False
75 supports_json_field_contains = False
76 supports_collation_on_textfield = False
77 supports_tuple_lookups = False
78 test_now_utc_template = "CURRENT_TIMESTAMP AT TIME ZONE 'UTC'"
79 django_test_expected_failures = {
80 # A bug in Django/oracledb with respect to string handling (#23843).
81 "annotations.tests.NonAggregateAnnotationTestCase.test_custom_functions",
82 "annotations.tests.NonAggregateAnnotationTestCase."
83 "test_custom_functions_can_ref_other_functions",
84 }
85 insert_test_table_with_defaults = (
86 "INSERT INTO {} VALUES (DEFAULT, DEFAULT, DEFAULT)"
87 )
88
89 @cached_property
90 def django_test_skips(self):
91 skips = {
92 "Oracle doesn't support SHA224.": {
93 "db_functions.text.test_sha224.SHA224Tests.test_basic",
94 "db_functions.text.test_sha224.SHA224Tests.test_transform",
95 },
96 "Oracle doesn't correctly calculate ISO 8601 week numbering before "
97 "1583 (the Gregorian calendar was introduced in 1582).": {
98 "db_functions.datetime.test_extract_trunc.DateFunctionTests."
99 "test_trunc_week_before_1000",
100 "db_functions.datetime.test_extract_trunc."
101 "DateFunctionWithTimeZoneTests.test_trunc_week_before_1000",
102 },
103 "Oracle doesn't support bitwise XOR.": {
104 "expressions.tests.ExpressionOperatorTests.test_lefthand_bitwise_xor",
105 "expressions.tests.ExpressionOperatorTests."
106 "test_lefthand_bitwise_xor_null",
107 "expressions.tests.ExpressionOperatorTests."
108 "test_lefthand_bitwise_xor_right_null",
109 },
110 "Oracle requires ORDER BY in row_number, ANSI:SQL doesn't.": {
111 "expressions_window.tests.WindowFunctionTests."
112 "test_row_number_no_ordering",
113 "prefetch_related.tests.PrefetchLimitTests.test_empty_order",
114 },
115 "Oracle doesn't support changing collations on indexed columns (#33671).": {
116 "migrations.test_operations.OperationTests."
117 "test_alter_field_pk_fk_db_collation",
118 },
119 "Oracle doesn't support comparing NCLOB to NUMBER.": {
120 "generic_relations_regress.tests.GenericRelationTests."
121 "test_textlink_filter",
122 },
123 "Oracle doesn't support casting filters to NUMBER.": {
124 "lookup.tests.LookupQueryingTests.test_aggregate_combined_lookup",
125 },
126 }
127 if self.connection.oracle_version < (23,):
128 skips.update(
129 {
130 "Raises ORA-00600 on Oracle < 23c: internal error code.": {
131 "model_fields.test_jsonfield.TestQuerying."
132 "test_usage_in_subquery",
133 },
134 }
135 )
136 if self.connection.is_pool:
137 skips.update(
138 {
139 "Pooling does not support persistent connections": {
140 "backends.base.test_base.ConnectionHealthChecksTests."
141 "test_health_checks_enabled",
142 "backends.base.test_base.ConnectionHealthChecksTests."
143 "test_health_checks_enabled_errors_occurred",
144 "backends.base.test_base.ConnectionHealthChecksTests."
145 "test_health_checks_disabled",
146 "backends.base.test_base.ConnectionHealthChecksTests."
147 "test_set_autocommit_health_checks_enabled",
148 "servers.tests.LiveServerTestCloseConnectionTest."
149 "test_closes_connections",
150 "backends.oracle.tests.TransactionalTests."
151 "test_password_with_at_sign",
152 },
153 }
154 )
155 if is_oracledb and self.connection.oracledb_version >= (2, 1, 2):
156 skips.update(
157 {
158 "python-oracledb 2.1.2+ no longer hides 'ORA-1403: no data found' "
159 "exceptions raised in database triggers.": {
160 "backends.oracle.tests.TransactionalTests."
161 "test_hidden_no_data_found_exception"
162 },
163 },
164 )
165 return skips
166
167 @cached_property
168 def introspected_field_types(self):
169 return {
170 **super().introspected_field_types,
171 "GenericIPAddressField": "CharField",
172 "PositiveBigIntegerField": "BigIntegerField",
173 "PositiveIntegerField": "IntegerField",
174 "PositiveSmallIntegerField": "IntegerField",
175 "SmallIntegerField": "IntegerField",
176 "TimeField": "DateTimeField",
177 }
178
179 @cached_property
180 def test_collations(self):
181 return {
182 "ci": "BINARY_CI",
183 "cs": "BINARY",
184 "non_default": "SWEDISH_CI",
185 "swedish_ci": "SWEDISH_CI",
186 "virtual": "SWEDISH_CI" if self.supports_collation_on_charfield else None,
187 }
188
189 @cached_property
190 def supports_collation_on_charfield(self):
191 sql = "SELECT CAST('a' AS VARCHAR2(4001))" + self.bare_select_suffix
192 with self.connection.cursor() as cursor:
193 try:
194 cursor.execute(sql)
195 except DatabaseError as e:
196 if e.args[0].code == 910:
197 return False
198 raise
199 return True
200
201 @cached_property
202 def supports_primitives_in_json_field(self):
203 return self.connection.oracle_version >= (21,)
204
205 @cached_property
206 def supports_frame_exclusion(self):
207 return self.connection.oracle_version >= (21,)
208
209 @cached_property
210 def supports_boolean_expr_in_select_clause(self):
211 return self.connection.oracle_version >= (23,)
212
213 @cached_property
214 def supports_comparing_boolean_expr(self):
215 return self.connection.oracle_version >= (23,)
216
217 @cached_property
218 def supports_aggregation_over_interval_types(self):
219 return self.connection.oracle_version >= (23,)
220
221 @cached_property
222 def bare_select_suffix(self):
223 return "" if self.connection.oracle_version >= (23,) else " FROM DUAL"