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):
|
309 | 309 | return False |
310 | 310 | |
311 | 311 | def _cursor(self): |
| 312 | new_connection = False |
312 | 313 | if not self._valid_connection(): |
| 314 | new_connection = True |
313 | 315 | kwargs = { |
314 | 316 | 'conv': django_conversions, |
315 | 317 | 'charset': 'utf8', |
… |
… |
class DatabaseWrapper(BaseDatabaseWrapper):
|
336 | 338 | self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode] |
337 | 339 | self.connection.encoders[SafeString] = self.connection.encoders[str] |
338 | 340 | 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) |
341 | 349 | |
342 | 350 | def _rollback(self): |
343 | 351 | try: |
diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
index 708e60d..92a7942 100644
a
|
b
|
class Queries4Tests(BaseQuerysetTest):
|
1070 | 1070 | ci3 = CategoryItem.objects.create(category=c3) |
1071 | 1071 | |
1072 | 1072 | 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() |
1077 | 1073 | self.assertEqual(qs.count(), 1) |
1078 | 1074 | self.assertQuerysetEqual(qs, [ci1.pk], lambda x: x.pk) |
1079 | 1075 | |
… |
… |
class Queries4Tests(BaseQuerysetTest):
|
1136 | 1132 | ci3 = CategoryItem.objects.create(category=c1) |
1137 | 1133 | |
1138 | 1134 | 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() |
1143 | 1135 | self.assertEqual(qs.count(), 1) |
1144 | 1136 | self.assertQuerysetEqual(qs, [ci1.pk], lambda x: x.pk) |
1145 | 1137 | |