Ticket #16809: mysql-set-sql_auto_is_null.patch

File mysql-set-sql_auto_is_null.patch, 2.6 KB (added by jamesp, 13 years ago)
  • django/db/backends/mysql/base.py

    diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
    index a22951a..e9f5b8b 100644
    a b class DatabaseWrapper(BaseDatabaseWrapper):  
    309309        return False
    310310
    311311    def _cursor(self):
     312        new_connection = False
    312313        if not self._valid_connection():
     314            new_connection = True
    313315            kwargs = {
    314316                'conv': django_conversions,
    315317                'charset': 'utf8',
    class DatabaseWrapper(BaseDatabaseWrapper):  
    336338            self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode]
    337339            self.connection.encoders[SafeString] = self.connection.encoders[str]
    338340            connection_created.send(sender=self.__class__, connection=self)
    339         cursor = CursorWrapper(self.connection.cursor())
    340         return cursor
     341        cursor = self.connection.cursor()
     342        if new_connection:
     343            # SQL_AUTO_IS_NULL in MySQL controls whether an AUTO_INCREMENT column
     344            # on a recently-inserted row will return when the field is tested for
     345            # NULL.  Disabling this value brings this aspect of MySQL in line with
     346            # SQL standards.
     347            cursor.execute('SET SQL_AUTO_IS_NULL = 0')
     348        return CursorWrapper(cursor)
    341349
    342350    def _rollback(self):
    343351        try:
  • tests/regressiontests/queries/tests.py

    diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
    index 708e60d..92a7942 100644
    a b class Queries4Tests(BaseQuerysetTest):  
    10701070        ci3 = CategoryItem.objects.create(category=c3)
    10711071
    10721072        qs = CategoryItem.objects.exclude(category__specialcategory__isnull=False)
    1073         # Under MySQL, this query gives incorrect values on the first attempt.
    1074         # If you run exactly the same query twice, it yields the right answer
    1075         # the second attempt. Oh, how we do love MySQL.
    1076         qs.count()
    10771073        self.assertEqual(qs.count(), 1)
    10781074        self.assertQuerysetEqual(qs, [ci1.pk], lambda x: x.pk)
    10791075
    class Queries4Tests(BaseQuerysetTest):  
    11361132        ci3 = CategoryItem.objects.create(category=c1)
    11371133
    11381134        qs = CategoryItem.objects.exclude(category__onetoonecategory__isnull=False)
    1139         # Under MySQL, this query gives incorrect values on the first attempt.
    1140         # If you run exactly the same query twice, it yields the right answer
    1141         # the second attempt. Oh, how we do love MySQL.
    1142         qs.count()
    11431135        self.assertEqual(qs.count(), 1)
    11441136        self.assertQuerysetEqual(qs, [ci1.pk], lambda x: x.pk)
    11451137
Back to Top