1
0
mirror of https://github.com/django/django.git synced 2024-12-22 09:05:43 +00:00

Fixed #33548 -- Used the ->> operator for KeyTransforms on SQLite 3.38+.

This commit is contained in:
Anže Pečar 2024-06-08 13:03:20 +02:00 committed by Sarah Boyce
parent cf03aa4e94
commit e456d5da3c

View File

@ -385,10 +385,16 @@ class KeyTransform(Transform):
datatype_values = ",".join(
[repr(datatype) for datatype in connection.ops.jsonfield_datatype_values]
)
return (
"(CASE WHEN JSON_TYPE(%s, %%s) IN (%s) "
"THEN JSON_TYPE(%s, %%s) ELSE JSON_EXTRACT(%s, %%s) END)"
) % (lhs, datatype_values, lhs, lhs), (tuple(params) + (json_path,)) * 3
if connection.get_database_version() >= (3, 38):
return (
"(CASE WHEN JSON_TYPE(%s, %%s) IN (%s) "
"THEN JSON_TYPE(%s, %%s) ELSE %s ->> %%s END)"
) % (lhs, datatype_values, lhs, lhs), (tuple(params) + (json_path,)) * 3
else:
return (
"(CASE WHEN JSON_TYPE(%s, %%s) IN (%s) "
"THEN JSON_TYPE(%s, %%s) ELSE JSON_EXTRACT(%s, %%s) END)"
) % (lhs, datatype_values, lhs, lhs), (tuple(params) + (json_path,)) * 3
class KeyTextTransform(KeyTransform):