10000 Fixed #36148 -- Enabled native tuple comparison lookups on SQLite 3.3… · django/django@4a3ad9e · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a3ad9e

Browse files
charettesfelixxm
authored andcommitted
Fixed #36148 -- Enabled native tuple comparison lookups on SQLite 3.37+ and Oracle 23.4+.
VALUES must be explicitly specified when declaring a sequence of tuples on SQLite < 3.37 but it's not required on >= 3.37. See sqlite/sqlite@9289f51 which addressed the last remaining issue with IN.
1 parent a0a765d commit 4a3ad9e

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

django/db/backends/oracle/features.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
8080
allows_multiple_constraints_on_same_fields = False
8181
supports_json_field_contains = False
8282
supports_collation_on_textfield = False
83-
supports_tuple_lookups = False
8483
test_now_utc_template = "CURRENT_TIMESTAMP AT TIME ZONE 'UTC'"
8584
django_test_expected_failures = {
8685
# A bug in Django/oracledb with respect to string handling (#23843).
@@ -217,3 +216,8 @@ def supports_aggregation_over_interval_types(self):
217216
@cached_property
218217
def bare_select_suffix(self):
219218
return "" if self.connection.oracle_version >= (23,) else " FROM DUAL"
219+
220+
@cached_property
221+
def supports_tuple_lookups(self):
222+
# Support is known to be missing on 23.2 but available on 23.4.
223+
return self.connection.oracle_version >= (23, 4)

django/db/backends/sqlite3/features.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
6161
insert_test_table_with_defaults = 'INSERT INTO {} ("null") VALUES (1)'
6262
supports_default_keyword_in_insert = False
6363
supports_unlimited_charfield = True
64-
supports_tuple_lookups = False
6564

6665
@cached_property
6766
def django_test_skips(self):

django/db/models/fields/tuple_lookups.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ def __len__(self):
2727
def __iter__(self):
2828
return iter(self.source_expressions)
2929

30+
def as_sqlite(self, compiler, connection):
31+
if connection.get_database_version() < (3, 37) and isinstance(
32+
first_expr := self.source_expressions[0], Tuple
33+
):
34+
first_expr = first_expr.copy()
35+
first_expr.function = "VALUES"
36+
return Tuple(first_expr, *self.source_expressions[1:]).as_sql(
37+
compiler, connection
38+
)
39+
return self.as_sql(compiler, connection)
40+
3041

3142
class TupleLookupMixin:
3243
allows_composite_expressions = True

0 commit comments

Comments
 (0)
0