Refs #21160 -- Replaced DatabaseFeatures.supports_1000_query_parameters by a DatabaseFeatures.max_query_params.
This commit is contained in:
parent
1b1ea63f6a
commit
f42c7cc87b
|
@ -90,8 +90,8 @@ class BaseDatabaseFeatures:
|
||||||
# Does the backend order NULL values as largest or smallest?
|
# Does the backend order NULL values as largest or smallest?
|
||||||
nulls_order_largest = False
|
nulls_order_largest = False
|
||||||
|
|
||||||
# Is there a 1000 item limit on query parameters?
|
# The database's limit on the number of query parameters.
|
||||||
supports_1000_query_parameters = True
|
max_query_params = None
|
||||||
|
|
||||||
# Can an object have an autoincrement primary key of 0? MySQL says No.
|
# Can an object have an autoincrement primary key of 0? MySQL says No.
|
||||||
allows_auto_pk_0 = True
|
allows_auto_pk_0 = True
|
||||||
|
|
|
@ -14,7 +14,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
||||||
test_db_allows_multiple_connections = False
|
test_db_allows_multiple_connections = False
|
||||||
supports_unspecified_pk = True
|
supports_unspecified_pk = True
|
||||||
supports_timezones = False
|
supports_timezones = False
|
||||||
supports_1000_query_parameters = False
|
max_query_params = 999
|
||||||
supports_mixed_date_datetime_comparisons = False
|
supports_mixed_date_datetime_comparisons = False
|
||||||
has_bulk_insert = True
|
has_bulk_insert = True
|
||||||
supports_foreign_keys = False
|
supports_foreign_keys = False
|
||||||
|
|
|
@ -21,8 +21,12 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
If there's only a single field to insert, the limit is 500
|
If there's only a single field to insert, the limit is 500
|
||||||
(SQLITE_MAX_COMPOUND_SELECT).
|
(SQLITE_MAX_COMPOUND_SELECT).
|
||||||
"""
|
"""
|
||||||
limit = 999 if len(fields) > 1 else 500
|
if len(fields) == 1:
|
||||||
return (limit // len(fields)) if len(fields) > 0 else len(objs)
|
return 500
|
||||||
|
elif len(fields) > 1:
|
||||||
|
return self.connection.features.max_query_params // len(fields)
|
||||||
|
else:
|
||||||
|
return len(objs)
|
||||||
|
|
||||||
def check_expression_support(self, expression):
|
def check_expression_support(self, expression):
|
||||||
bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
|
bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
|
||||||
|
|
|
@ -2523,32 +2523,17 @@ class ConditionalTests(TestCase):
|
||||||
self.assertEqual(sql.find(fragment, pos + 1), -1)
|
self.assertEqual(sql.find(fragment, pos + 1), -1)
|
||||||
self.assertEqual(sql.find("NULL", pos + len(fragment)), pos + len(fragment))
|
self.assertEqual(sql.find("NULL", pos + len(fragment)), pos + len(fragment))
|
||||||
|
|
||||||
# Sqlite 3 does not support passing in more than 1000 parameters except by
|
def test_in_list_limit(self):
|
||||||
# changing a parameter at compilation time.
|
|
||||||
@skipUnlessDBFeature('supports_1000_query_parameters')
|
|
||||||
def test_ticket14244(self):
|
|
||||||
# The "in" lookup works with lists of 1000 items or more.
|
# The "in" lookup works with lists of 1000 items or more.
|
||||||
# The numbers amount is picked to force three different IN batches
|
# The numbers amount is picked to force three different IN batches
|
||||||
# for Oracle, yet to be less than 2100 parameter limit for MSSQL.
|
# for Oracle, yet to be less than 2100 parameter limit for MSSQL.
|
||||||
numbers = list(range(2050))
|
numbers = list(range(2050))
|
||||||
Number.objects.all().delete()
|
max_query_params = connection.features.max_query_params
|
||||||
Number.objects.bulk_create(Number(num=num) for num in numbers)
|
if max_query_params is None or max_query_params >= len(numbers):
|
||||||
self.assertEqual(
|
Number.objects.bulk_create(Number(num=num) for num in numbers)
|
||||||
Number.objects.filter(num__in=numbers[:1000]).count(),
|
for number in [1000, 1001, 2000, len(numbers)]:
|
||||||
1000
|
with self.subTest(number=number):
|
||||||
)
|
self.assertEqual(Number.objects.filter(num__in=numbers[:number]).count(), number)
|
||||||
self.assertEqual(
|
|
||||||
Number.objects.filter(num__in=numbers[:1001]).count(),
|
|
||||||
1001
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
Number.objects.filter(num__in=numbers[:2000]).count(),
|
|
||||||
2000
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
Number.objects.filter(num__in=numbers).count(),
|
|
||||||
len(numbers)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class UnionTests(unittest.TestCase):
|
class UnionTests(unittest.TestCase):
|
||||||
|
|
Loading…
Reference in New Issue