| 1 |
import operator |
| 2 |
|
| 3 |
from django.db import transaction |
| 4 |
from django.db.backends.base.features import BaseDatabaseFeatures |
| 5 |
from django.db.utils import OperationalError |
| 6 |
from django.utils.functional import cached_property |
| 7 |
|
| 8 |
from .base import Database |
| 9 |
|
| 10 |
|
| 11 |
class DatabaseFeatures(BaseDatabaseFeatures): |
| 12 |
minimum_database_version = (3, 31) |
| 13 |
test_db_allows_multiple_connections = False |
| 14 |
supports_unspecified_pk = True |
| 15 |
supports_timezones = False |
| 16 |
max_query_params = 999 |
| 17 |
supports_transactions = True |
| 18 |
atomic_transactions = False |
| 19 |
can_rollback_ddl = True |
| 20 |
can_create_inline_fk = False |
| 21 |
requires_literal_defaults = True |
| 22 |
can_clone_databases = True |
| 23 |
supports_temporal_subtraction = True |
| 24 |
ignores_table_name_case = True |
| 25 |
supports_cast_with_precision = False |
| 26 |
time_cast_precision = 3 |
| 27 |
can_release_savepoints = True |
| 28 |
has_case_insensitive_like = True |
| 29 |
# Is "ALTER TABLE ... DROP COLUMN" supported? |
| 30 |
can_alter_table_drop_column = Database.sqlite_version_info >= (3, 35, 5) |
| 31 |
supports_parentheses_in_compound = False |
| 32 |
can_defer_constraint_checks = True |
| 33 |
supports_over_clause = True |
| 34 |
supports_frame_range_fixed_distance = True |
| 35 |
supports_frame_exclusion = True |
| 36 |
supports_aggregate_filter_clause = True |
| 37 |
order_by_nulls_first = True |
| 38 |
supports_json_field_contains = False |
| 39 |
supports_update_conflicts = True |
| 40 |
supports_update_conflicts_with_target = True |
| 41 |
supports_stored_generated_columns = True |
| 42 |
supports_virtual_generated_columns = True |
| 43 |
test_collations = { |
| 44 |
"ci": "nocase", |
| 45 |
"cs": "binary", |
| 46 |
"non_default": "nocase", |
| 47 |
"virtual": "nocase", |
| 48 |
} |
| 49 |
django_test_expected_failures = { |
| 50 |
# The django_format_dtdelta() function doesn't properly handle mixed |
| 51 |
# Date/DateTime fields and timedeltas. |
| 52 |
"expressions.tests.FTimeDeltaTests.test_mixed_comparisons1", |
| 53 |
} |
| 54 |
insert_test_table_with_defaults = 'INSERT INTO {} ("null") VALUES (1)' |
| 55 |
supports_default_keyword_in_insert = False |
| 56 |
supports_unlimited_charfield = True |
| 57 |
supports_tuple_lookups = False |
| 58 |
|
| 59 |
@cached_property |
| 60 |
def django_test_skips(self): |
| 61 |
skips = { |
| 62 |
"SQLite stores values rounded to 15 significant digits.": { |
| 63 |
"model_fields.test_decimalfield.DecimalFieldTests." |
| 64 |
"test_fetch_from_db_without_float_rounding", |
| 65 |
}, |
| 66 |
"SQLite naively remakes the table on field alteration.": { |
| 67 |
"schema.tests.SchemaTests.test_unique_no_unnecessary_fk_drops", |
| 68 |
"schema.tests.SchemaTests.test_unique_and_reverse_m2m", |
| 69 |
"schema.tests.SchemaTests." |
| 70 |
"test_alter_field_default_doesnt_perform_queries", |
| 71 |
"schema.tests.SchemaTests." |
| 72 |
"test_rename_column_renames_deferred_sql_references", |
| 73 |
}, |
| 74 |
"SQLite doesn't support negative precision for ROUND().": { |
| 75 |
"db_functions.math.test_round.RoundTests." |
| 76 |
"test_null_with_negative_precision", |
| 77 |
"db_functions.math.test_round.RoundTests." |
| 78 |
"test_decimal_with_negative_precision", |
| 79 |
"db_functions.math.test_round.RoundTests." |
| 80 |
"test_float_with_negative_precision", |
| 81 |
"db_functions.math.test_round.RoundTests." |
| 82 |
"test_integer_with_negative_precision", |
| 83 |
}, |
| 84 |
"The actual query cannot be determined on SQLite": { |
| 85 |
"backends.base.test_base.ExecuteWrapperTests.test_wrapper_debug", |
| 86 |
}, |
| 87 |
} |
| 88 |
if self.connection.is_in_memory_db(): |
| 89 |
skips.update( |
| 90 |
{ |
| 91 |
"the sqlite backend's close() method is a no-op when using an " |
| 92 |
"in-memory database": { |
| 93 |
"servers.test_liveserverthread.LiveServerThreadTest." |
| 94 |
"test_closes_connections", |
| 95 |
"servers.tests.LiveServerTestCloseConnectionTest." |
| 96 |
"test_closes_connections", |
| 97 |
}, |
| 98 |
"For SQLite in-memory tests, closing the connection destroys " |
| 99 |
"the database.": { |
| 100 |
"test_utils.tests.AssertNumQueriesUponConnectionTests." |
| 101 |
"test_ignores_connection_configuration_queries", |
| 102 |
}, |
| 103 |
} |
| 104 |
) |
| 105 |
else: |
| 106 |
skips.update( |
| 107 |
{ |
| 108 |
"Only connections to in-memory SQLite databases are passed to the " |
| 109 |
"server thread.": { |
| 110 |
"servers.tests.LiveServerInMemoryDatabaseLockTest." |
| 111 |
"test_in_memory_database_lock", |
| 112 |
}, |
| 113 |
"multiprocessing's start method is checked only for in-memory " |
| 114 |
"SQLite databases": { |
| 115 |
"backends.sqlite.test_creation.TestDbSignatureTests." |
| 116 |
"test_get_test_db_clone_settings_not_supported", |
| 117 |
}, |
| 118 |
} |
| 119 |
) |
| 120 |
if Database.sqlite_version_info < (3, 47): |
| 121 |
skips.update( |
| 122 |
{ |
| 123 |
"SQLite does not parse escaped double quotes in the JSON path " |
| 124 |
"notation": { |
| 125 |
"model_fields.test_jsonfield.TestQuerying." |
| 126 |
"test_lookups_special_chars_double_quotes", |
| 127 |
}, |
| 128 |
} |
| 129 |
) |
| 130 |
return skips |
| 131 |
|
| 132 |
@cached_property |
| 133 |
def introspected_field_types(self): |
| 134 |
return { |
| 135 |
**super().introspected_field_types, |
| 136 |
"BigAutoField": "AutoField", |
| 137 |
"DurationField": "BigIntegerField", |
| 138 |
"GenericIPAddressField": "CharField", |
| 139 |
"SmallAutoField": "AutoField", |
| 140 |
} |
| 141 |
|
| 142 |
@cached_property |
| 143 |
def supports_json_field(self): |
| 144 |
with self.connection.cursor() as cursor: |
| 145 |
try: |
| 146 |
with transaction.atomic(self.connection.alias): |
| 147 |
cursor.execute('SELECT JSON(\'{"a": "b"}\')') |
| 148 |
except OperationalError: |
| 149 |
return False |
| 150 |
return True |
| 151 |
|
| 152 |
can_introspect_json_field = property(operator.attrgetter("supports_json_field")) |
| 153 |
has_json_object_function = property(operator.attrgetter("supports_json_field")) |
| 154 |
|
| 155 |
@cached_property |
| 156 |
def can_return_columns_from_insert(self): |
| 157 |
return Database.sqlite_version_info >= (3, 35) |
| 158 |
|
| 159 |
can_return_rows_from_bulk_insert = property( |
| 160 |
operator.attrgetter("can_return_columns_from_insert") |
| 161 |
) |