diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-03-03 08:30:37 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-03-03 11:25:37 +0100 |
| commit | a19505eb2ecd4a07ff39f3f66898e68b69d0e680 (patch) | |
| tree | 0fc38266525f25b62aa5801ff5da73d1daef30e7 /django | |
| parent | 7b8fa1653fde578ab3a496d9974ab1d4261b8b26 (diff) | |
Refs #31331 -- Added DatabaseWrapper.sql_mode to MySQL.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/mysql/base.py | 7 | ||||
| -rw-r--r-- | django/db/backends/mysql/validation.py | 6 |
2 files changed, 8 insertions, 5 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index be00024849..eb0ba18cda 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -364,3 +364,10 @@ class DatabaseWrapper(BaseDatabaseWrapper): @cached_property def mysql_is_mariadb(self): return 'mariadb' in self.mysql_server_info.lower() + + @cached_property + def sql_mode(self): + with self.cursor() as cursor: + cursor.execute('SELECT @@sql_mode') + sql_mode = cursor.fetchone() + return set(sql_mode[0].split(',') if sql_mode else ()) diff --git a/django/db/backends/mysql/validation.py b/django/db/backends/mysql/validation.py index 9def8e57f8..ee1c360e35 100644 --- a/django/db/backends/mysql/validation.py +++ b/django/db/backends/mysql/validation.py @@ -10,11 +10,7 @@ class DatabaseValidation(BaseDatabaseValidation): return issues def _check_sql_mode(self, **kwargs): - with self.connection.cursor() as cursor: - cursor.execute("SELECT @@sql_mode") - sql_mode = cursor.fetchone() - modes = set(sql_mode[0].split(',') if sql_mode else ()) - if not (modes & {'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES'}): + if not (self.connection.sql_mode & {'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES'}): return [checks.Warning( "MySQL Strict Mode is not set for database connection '%s'" % self.connection.alias, hint="MySQL's Strict Mode fixes many data integrity problems in MySQL, " |
