diff options
| author | Stewart Park <stewartpark92@gmail.com> | 2015-12-14 18:19:40 -0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-12-15 10:30:57 -0500 |
| commit | b7fdd60d85ee94df444369be1b2c778cda44a0c2 (patch) | |
| tree | 5e4518d062f2361d5e4615ac381d557787321d37 /django | |
| parent | 3d2236773ba88e330841b8c72183b0e978e10909 (diff) | |
Fixed #24675 -- Skipped SQL_AUTO_IS_NULL query on MySQL if not needed.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/mysql/base.py | 13 | ||||
| -rw-r--r-- | django/db/backends/mysql/features.py | 6 |
2 files changed, 13 insertions, 6 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 03f3857664..6fbf15e42e 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -267,12 +267,13 @@ class DatabaseWrapper(BaseDatabaseWrapper): return conn def init_connection_state(self): - with self.cursor() as cursor: - # SQL_AUTO_IS_NULL in MySQL controls whether an AUTO_INCREMENT column - # on a recently-inserted row will return when the field is tested for - # NULL. Disabling this value brings this aspect of MySQL in line with - # SQL standards. - cursor.execute('SET SQL_AUTO_IS_NULL = 0') + if self.features.is_sql_auto_is_null_enabled: + with self.cursor() as cursor: + # SQL_AUTO_IS_NULL controls whether an AUTO_INCREMENT column on + # a recently inserted row will return when the field is tested + # for NULL. Disabling this brings this aspect of MySQL in line + # with SQL standards. + cursor.execute('SET SQL_AUTO_IS_NULL = 0') def create_cursor(self): cursor = self.connection.cursor() diff --git a/django/db/backends/mysql/features.py b/django/db/backends/mysql/features.py index c8ea8f7fb6..075b68a872 100644 --- a/django/db/backends/mysql/features.py +++ b/django/db/backends/mysql/features.py @@ -69,3 +69,9 @@ class DatabaseFeatures(BaseDatabaseFeatures): def introspected_boolean_field_type(self, *args, **kwargs): return 'IntegerField' + + @cached_property + def is_sql_auto_is_null_enabled(self): + with self.connection.cursor() as cursor: + cursor.execute('SELECT @@SQL_AUTO_IS_NULL') + return cursor.fetchone()[0] == 1 |
