Refs #30581 -- Fixed DatabaseFeatures.bare_select_suffix on MySQL < 8 and MariaDB < 10.4.

This commit is contained in:
Gagaro 2022-03-22 09:11:46 +01:00 committed by Mariusz Felisiak
parent f77216bd1a
commit 7325d29152
2 changed files with 17 additions and 0 deletions

View File

@ -56,6 +56,17 @@ class DatabaseFeatures(BaseDatabaseFeatures):
else: else:
return (5, 7) return (5, 7)
@cached_property
def bare_select_suffix(self):
if (
self.connection.mysql_is_mariadb and self.connection.mysql_version < (10, 4)
) or (
not self.connection.mysql_is_mariadb
and self.connection.mysql_version < (8,)
):
return " FROM DUAL"
return ""
@cached_property @cached_property
def test_collations(self): def test_collations(self):
charset = "utf8" charset = "utf8"

View File

@ -548,6 +548,12 @@ class BackendTestCase(TransactionTestCase):
) )
self.assertEqual(tuple(kwargs["extra"].values()), params[1:]) self.assertEqual(tuple(kwargs["extra"].values()), params[1:])
def test_queries_bare_where(self):
sql = f"SELECT 1{connection.features.bare_select_suffix} WHERE 1=1"
with connection.cursor() as cursor:
cursor.execute(sql)
self.assertEqual(cursor.fetchone(), (1,))
def test_timezone_none_use_tz_false(self): def test_timezone_none_use_tz_false(self):
connection.ensure_connection() connection.ensure_connection()
with self.settings(TIME_ZONE=None, USE_TZ=False): with self.settings(TIME_ZONE=None, USE_TZ=False):