Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/django/db/backends/base/features.py: 89%

142 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1from django.db import ProgrammingError 

2from django.utils.functional import cached_property 

3 

4 

5class BaseDatabaseFeatures: 

6 gis_enabled = False 

7 # Oracle can't group by LOB (large object) data types. 

8 allows_group_by_lob = True 

9 allows_group_by_pk = False 

10 allows_group_by_selected_pks = False 

11 empty_fetchmany_value = [] 

12 update_can_self_select = True 

13 

14 # Does the backend distinguish between '' and None? 

15 interprets_empty_strings_as_nulls = False 

16 

17 # Does the backend allow inserting duplicate NULL rows in a nullable 

18 # unique field? All core backends implement this correctly, but other 

19 # databases such as SQL Server do not. 

20 supports_nullable_unique_constraints = True 

21 

22 # Does the backend allow inserting duplicate rows when a unique_together 

23 # constraint exists and some fields are nullable but not all of them? 

24 supports_partially_nullable_unique_constraints = True 

25 # Does the backend support initially deferrable unique constraints? 

26 supports_deferrable_unique_constraints = False 

27 

28 can_use_chunked_reads = True 

29 can_return_columns_from_insert = False 

30 can_return_rows_from_bulk_insert = False 

31 has_bulk_insert = True 

32 uses_savepoints = True 

33 can_release_savepoints = False 

34 

35 # If True, don't use integer foreign keys referring to, e.g., positive 

36 # integer primary keys. 

37 related_fields_match_type = False 

38 allow_sliced_subqueries_with_in = True 

39 has_select_for_update = False 

40 has_select_for_update_nowait = False 

41 has_select_for_update_skip_locked = False 

42 has_select_for_update_of = False 

43 has_select_for_no_key_update = False 

44 # Does the database's SELECT FOR UPDATE OF syntax require a column rather 

45 # than a table? 

46 select_for_update_of_column = False 

47 

48 # Does the default test database allow multiple connections? 

49 # Usually an indication that the test database is in-memory 

50 test_db_allows_multiple_connections = True 

51 

52 # Can an object be saved without an explicit primary key? 

53 supports_unspecified_pk = False 

54 

55 # Can a fixture contain forward references? i.e., are 

56 # FK constraints checked at the end of transaction, or 

57 # at the end of each save operation? 

58 supports_forward_references = True 

59 

60 # Does the backend truncate names properly when they are too long? 

61 truncates_names = False 

62 

63 # Is there a REAL datatype in addition to floats/doubles? 

64 has_real_datatype = False 

65 supports_subqueries_in_group_by = True 

66 

67 # Does the backend ignore unnecessary ORDER BY clauses in subqueries? 

68 ignores_unnecessary_order_by_in_subqueries = True 

69 

70 # Is there a true datatype for uuid? 

71 has_native_uuid_field = False 

72 

73 # Is there a true datatype for timedeltas? 

74 has_native_duration_field = False 

75 

76 # Does the database driver supports same type temporal data subtraction 

77 # by returning the type used to store duration field? 

78 supports_temporal_subtraction = False 

79 

80 # Does the __regex lookup support backreferencing and grouping? 

81 supports_regex_backreferencing = True 

82 

83 # Can date/datetime lookups be performed using a string? 

84 supports_date_lookup_using_string = True 

85 

86 # Can datetimes with timezones be used? 

87 supports_timezones = True 

88 

89 # Does the database have a copy of the zoneinfo database? 

90 has_zoneinfo_database = True 

91 

92 # When performing a GROUP BY, is an ORDER BY NULL required 

93 # to remove any ordering? 

94 requires_explicit_null_ordering_when_grouping = False 

95 

96 # Does the backend order NULL values as largest or smallest? 

97 nulls_order_largest = False 

98 

99 # Does the backend support NULLS FIRST and NULLS LAST in ORDER BY? 

100 supports_order_by_nulls_modifier = True 

101 

102 # Does the backend orders NULLS FIRST by default? 

103 order_by_nulls_first = False 

104 

105 # The database's limit on the number of query parameters. 

106 max_query_params = None 

107 

108 # Can an object have an autoincrement primary key of 0? 

109 allows_auto_pk_0 = True 

110 

111 # Do we need to NULL a ForeignKey out, or can the constraint check be 

112 # deferred 

113 can_defer_constraint_checks = False 

114 

115 # date_interval_sql can properly handle mixed Date/DateTime fields and timedeltas 

116 supports_mixed_date_datetime_comparisons = True 

117 

118 # Does the backend support tablespaces? Default to False because it isn't 

119 # in the SQL standard. 

120 supports_tablespaces = False 

121 

122 # Does the backend reset sequences between tests? 

123 supports_sequence_reset = True 

124 

125 # Can the backend introspect the default value of a column? 

126 can_introspect_default = True 

127 

128 # Confirm support for introspected foreign keys 

129 # Every database can do this reliably, except MySQL, 

130 # which can't do it for MyISAM tables 

131 can_introspect_foreign_keys = True 

132 

133 # Map fields which some backends may not be able to differentiate to the 

134 # field it's introspected as. 

135 introspected_field_types = { 

136 "AutoField": "AutoField", 

137 "BigAutoField": "BigAutoField", 

138 "BigIntegerField": "BigIntegerField", 

139 "BinaryField": "BinaryField", 

140 "BooleanField": "BooleanField", 

141 "CharField": "CharField", 

142 "DurationField": "DurationField", 

143 "GenericIPAddressField": "GenericIPAddressField", 

144 "IntegerField": "IntegerField", 

145 "PositiveBigIntegerField": "PositiveBigIntegerField", 

146 "PositiveIntegerField": "PositiveIntegerField", 

147 "PositiveSmallIntegerField": "PositiveSmallIntegerField", 

148 "SmallAutoField": "SmallAutoField", 

149 "SmallIntegerField": "SmallIntegerField", 

150 "TimeField": "TimeField", 

151 } 

152 

153 # Can the backend introspect the column order (ASC/DESC) for indexes? 

154 supports_index_column_ordering = True 

155 

156 # Does the backend support introspection of materialized views? 

157 can_introspect_materialized_views = False 

158 

159 # Support for the DISTINCT ON clause 

160 can_distinct_on_fields = False 

161 

162 # Does the backend prevent running SQL queries in broken transactions? 

163 atomic_transactions = True 

164 

165 # Can we roll back DDL in a transaction? 

166 can_rollback_ddl = False 

167 

168 # Does it support operations requiring references rename in a transaction? 

169 supports_atomic_references_rename = True 

170 

171 # Can we issue more than one ALTER COLUMN clause in an ALTER TABLE? 

172 supports_combined_alters = False 

173 

174 # Does it support foreign keys? 

175 supports_foreign_keys = True 

176 

177 # Can it create foreign key constraints inline when adding columns? 

178 can_create_inline_fk = True 

179 

180 # Does it automatically index foreign keys? 

181 indexes_foreign_keys = True 

182 

183 # Does it support CHECK constraints? 

184 supports_column_check_constraints = True 

185 supports_table_check_constraints = True 

186 # Does the backend support introspection of CHECK constraints? 

187 can_introspect_check_constraints = True 

188 

189 # Does the backend support 'pyformat' style ("... %(name)s ...", {'name': value}) 

190 # parameter passing? Note this can be provided by the backend even if not 

191 # supported by the Python driver 

192 supports_paramstyle_pyformat = True 

193 

194 # Does the backend require literal defaults, rather than parameterized ones? 

195 requires_literal_defaults = False 

196 

197 # Does the backend require a connection reset after each material schema change? 

198 connection_persists_old_columns = False 

199 

200 # What kind of error does the backend throw when accessing closed cursor? 

201 closed_cursor_error_class = ProgrammingError 

202 

203 # Does 'a' LIKE 'A' match? 

204 has_case_insensitive_like = True 

205 

206 # Suffix for backends that don't support "SELECT xxx;" queries. 

207 bare_select_suffix = "" 

208 

209 # If NULL is implied on columns without needing to be explicitly specified 

210 implied_column_null = False 

211 

212 # Does the backend support "select for update" queries with limit (and offset)? 

213 supports_select_for_update_with_limit = True 

214 

215 # Does the backend ignore null expressions in GREATEST and LEAST queries unless 

216 # every expression is null? 

217 greatest_least_ignores_nulls = False 

218 

219 # Can the backend clone databases for parallel test execution? 

220 # Defaults to False to allow third-party backends to opt-in. 

221 can_clone_databases = False 

222 

223 # Does the backend consider table names with different casing to 

224 # be equal? 

225 ignores_table_name_case = False 

226 

227 # Place FOR UPDATE right after FROM clause. Used on MSSQL. 

228 for_update_after_from = False 

229 

230 # Combinatorial flags 

231 supports_select_union = True 

232 supports_select_intersection = True 

233 supports_select_difference = True 

234 supports_slicing_ordering_in_compound = False 

235 supports_parentheses_in_compound = True 

236 

237 # Does the database support SQL 2003 FILTER (WHERE ...) in aggregate 

238 # expressions? 

239 supports_aggregate_filter_clause = False 

240 

241 # Does the backend support indexing a TextField? 

242 supports_index_on_text_field = True 

243 

244 # Does the backend support window expressions (expression OVER (...))? 

245 supports_over_clause = False 

246 supports_frame_range_fixed_distance = False 

247 only_supports_unbounded_with_preceding_and_following = False 

248 

249 # Does the backend support CAST with precision? 

250 supports_cast_with_precision = True 

251 

252 # How many second decimals does the database return when casting a value to 

253 # a type with time? 

254 time_cast_precision = 6 

255 

256 # SQL to create a procedure for use by the Django test suite. The 

257 # functionality of the procedure isn't important. 

258 create_test_procedure_without_params_sql = None 

259 create_test_procedure_with_int_param_sql = None 

260 

261 # Does the backend support keyword parameters for cursor.callproc()? 

262 supports_callproc_kwargs = False 

263 

264 # What formats does the backend EXPLAIN syntax support? 

265 supported_explain_formats = set() 

266 

267 # Does DatabaseOperations.explain_query_prefix() raise ValueError if 

268 # unknown kwargs are passed to QuerySet.explain()? 

269 validates_explain_options = True 

270 

271 # Does the backend support the default parameter in lead() and lag()? 

272 supports_default_in_lead_lag = True 

273 

274 # Does the backend support ignoring constraint or uniqueness errors during 

275 # INSERT? 

276 supports_ignore_conflicts = True 

277 

278 # Does this backend require casting the results of CASE expressions used 

279 # in UPDATE statements to ensure the expression has the correct type? 

280 requires_casted_case_in_updates = False 

281 

282 # Does the backend support partial indexes (CREATE INDEX ... WHERE ...)? 

283 supports_partial_indexes = True 

284 supports_functions_in_partial_indexes = True 

285 # Does the backend support covering indexes (CREATE INDEX ... INCLUDE ...)? 

286 supports_covering_indexes = False 

287 # Does the backend support indexes on expressions? 

288 supports_expression_indexes = True 

289 # Does the backend treat COLLATE as an indexed expression? 

290 collate_as_index_expression = False 

291 

292 # Does the database allow more than one constraint or index on the same 

293 # field(s)? 

294 allows_multiple_constraints_on_same_fields = True 

295 

296 # Does the backend support boolean expressions in SELECT and GROUP BY 

297 # clauses? 

298 supports_boolean_expr_in_select_clause = True 

299 

300 # Does the backend support JSONField? 

301 supports_json_field = True 

302 # Can the backend introspect a JSONField? 

303 can_introspect_json_field = True 

304 # Does the backend support primitives in JSONField? 

305 supports_primitives_in_json_field = True 

306 # Is there a true datatype for JSON? 

307 has_native_json_field = False 

308 # Does the backend use PostgreSQL-style JSON operators like '->'? 

309 has_json_operators = False 

310 # Does the backend support __contains and __contained_by lookups for 

311 # a JSONField? 

312 supports_json_field_contains = True 

313 # Does value__d__contains={'f': 'g'} (without a list around the dict) match 

314 # {'d': [{'f': 'g'}]}? 

315 json_key_contains_list_matching_requires_list = False 

316 # Does the backend support JSONObject() database function? 

317 has_json_object_function = True 

318 

319 # Does the backend support column collations? 

320 supports_collation_on_charfield = True 

321 supports_collation_on_textfield = True 

322 # Does the backend support non-deterministic collations? 

323 supports_non_deterministic_collations = True 

324 

325 # Collation names for use by the Django test suite. 

326 test_collations = { 

327 "ci": None, # Case-insensitive. 

328 "cs": None, # Case-sensitive. 

329 "non_default": None, # Non-default. 

330 "swedish_ci": None, # Swedish case-insensitive. 

331 } 

332 # SQL template override for tests.aggregation.tests.NowUTC 

333 test_now_utc_template = None 

334 

335 # A set of dotted paths to tests in Django's test suite that are expected 

336 # to fail on this database. 

337 django_test_expected_failures = set() 

338 # A map of reasons to sets of dotted paths to tests in Django's test suite 

339 # that should be skipped for this database. 

340 django_test_skips = {} 

341 

342 def __init__(self, connection): 

343 self.connection = connection 

344 

345 @cached_property 

346 def supports_explaining_query_execution(self): 

347 """Does this backend support explaining query execution?""" 

348 return self.connection.ops.explain_prefix is not None 

349 

350 @cached_property 

351 def supports_transactions(self): 

352 """Confirm support for transactions.""" 

353 with self.connection.cursor() as cursor: 

354 cursor.execute("CREATE TABLE ROLLBACK_TEST (X INT)") 

355 self.connection.set_autocommit(False) 

356 cursor.execute("INSERT INTO ROLLBACK_TEST (X) VALUES (8)") 

357 self.connection.rollback() 

358 self.connection.set_autocommit(True) 

359 cursor.execute("SELECT COUNT(X) FROM ROLLBACK_TEST") 

360 (count,) = cursor.fetchone() 

361 cursor.execute("DROP TABLE ROLLBACK_TEST") 

362 return count == 0 

363 

364 def allows_group_by_selected_pks_on_model(self, model): 

365 if not self.allows_group_by_selected_pks: 

366 return False 

367 return model._meta.managed