#24675: Skip "SET SQL_AUTO_IS_NULL = 0" on versions of MySQL that don't need it
-------------------------------------+-------------------------------------
     Reporter:  ssjunior             |                    Owner:  ssjunior
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Database layer       |                  Version:  1.8
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  mysql                |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by ssjunior):

 I think that I have a better solution. Check in the features for the
 status on the server and issue the command only if it is True on the
 server. Tell me what do you think and if it is ok I will submitt a new PR.

 
https://github.com/ssjunior/django/commit/52bf6c7630ab6b17a3a3ff64213e1ad36d6fe270

 {{{
     @cached_property
     def sql_auto_is_null(self):
         "Return if server global variable sql_auto_is_null is set to True"
         with self.connection.cursor() as cursor:
             cursor.execute("SHOW GLOBAL VARIABLES LIKE
 'sql_auto_is_null'")
             return cursor.fetchone()[1] == 'ON'


     def init_connection_state(self):
         # 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.
         # Check the sql_auto_is_null status on the MySQL server and if
 necessary
         # set it to False.
         if self.features.sql_auto_is_null:
             with self.cursor() as cursor:
                 cursor.execute('SET SQL_AUTO_IS_NULL = 0')

 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.af5fe330bd639a8e63e4fec3cf686717%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to