diff options
| -rw-r--r-- | django/db/backends/mysql/features.py | 11 | ||||
| -rw-r--r-- | tests/backends/tests.py | 6 |
2 files changed, 17 insertions, 0 deletions
diff --git a/django/db/backends/mysql/features.py b/django/db/backends/mysql/features.py index 357e431524..834ea4f88f 100644 --- a/django/db/backends/mysql/features.py +++ b/django/db/backends/mysql/features.py @@ -57,6 +57,17 @@ class DatabaseFeatures(BaseDatabaseFeatures): 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 def test_collations(self): charset = "utf8" if self.connection.mysql_is_mariadb and self.connection.mysql_version >= ( diff --git a/tests/backends/tests.py b/tests/backends/tests.py index 28e00a04ca..85b0e55cb0 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -548,6 +548,12 @@ class BackendTestCase(TransactionTestCase): ) 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): connection.ensure_connection() with self.settings(TIME_ZONE=None, USE_TZ=False): |
