Ticket #19954: 19954-1.diff

File 19954-1.diff, 2.7 KB (added by Claude Paroz, 12 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 6b2ecae..deb4ce6 100644
    a b class DatabaseOperations(BaseDatabaseOperations):  
    269269        # With MySQLdb, cursor objects have an (undocumented) "_last_executed"
    270270        # attribute where the exact query sent to the database is saved.
    271271        # See MySQLdb/cursors.py in the source distribution.
    272         return cursor._last_executed.decode('utf-8')
     272        def to_unicode(chunk):
     273            try:
     274                return chunk.decode('utf-8')
     275            except UnicodeDecodeError:
     276                return chunk.decode('unicode-escape')
     277        try:
     278            return cursor._last_executed.decode('utf-8')
     279        except UnicodeDecodeError:
     280            return ' '.join(to_unicode(chunk) for chunk in cursor._last_executed.split(b' '))
    273281
    274282    def no_limit_value(self):
    275283        # 2**64 - 1, as recommended by the MySQL documentation
  • tests/backends/models.py

    diff --git a/tests/backends/models.py b/tests/backends/models.py
    index 5876cbe..036be93 100644
    a b class Post(models.Model):  
    6262class Reporter(models.Model):
    6363    first_name = models.CharField(max_length=30)
    6464    last_name = models.CharField(max_length=30)
     65    raw_data = models.BinaryField()
    6566
    6667    def __str__(self):
    6768        return "%s %s" % (self.first_name, self.last_name)
  • tests/backends/tests.py

    diff --git a/tests/backends/tests.py b/tests/backends/tests.py
    index 7c68863..59dace2 100644
    a b class DateQuotingTest(TestCase):  
    157157class LastExecutedQueryTest(TestCase):
    158158
    159159    def test_debug_sql(self):
    160         list(models.Tag.objects.filter(name="test"))
     160        list(models.Reporter.objects.filter(first_name="test"))
    161161        sql = connection.queries[-1]['sql'].lower()
    162162        self.assertIn("select", sql)
    163         self.assertIn(models.Tag._meta.db_table, sql)
     163        self.assertIn(models.Reporter._meta.db_table, sql)
    164164
    165165    def test_query_encoding(self):
    166166        """
    167167        Test that last_executed_query() returns an Unicode string
    168168        """
    169         tags = models.Tag.objects.extra(select={'föö': 1})
    170         sql, params = tags.query.sql_with_params()
    171         cursor = tags.query.get_compiler('default').execute_sql(None)
     169        persons = models.Reporter.objects.filter(raw_data=b'\x00\x46  \xFE').extra(select={'föö': 1})
     170        sql, params = persons.query.sql_with_params()
     171        cursor = persons.query.get_compiler('default').execute_sql(None)
    172172        last_sql = cursor.db.ops.last_executed_query(cursor, sql, params)
    173173        self.assertTrue(isinstance(last_sql, six.text_type))
    174174
Back to Top