From 6929c0d4d1d3b4611db0f8852772e1c2b87f8245 Mon Sep 17 00:00:00 2001 From: Ian Kelly Date: Fri, 4 Jan 2008 22:51:22 +0000 Subject: [PATCH] Fixed #6254: Made fetchone() in the oracle backend correctly convert strings to unicode objects. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6995 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/oracle/base.py | 5 ++++- tests/regressiontests/backends/models.py | 28 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 5dd62432c5..70f5688d1a 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -516,7 +516,10 @@ class FormatStylePlaceholderCursor(Database.Cursor): return Database.Cursor.executemany(self, query, new_param_list) def fetchone(self): - return to_unicode(Database.Cursor.fetchone(self)) + row = Database.Cursor.fetchone(self) + if row is None: + return row + return tuple([to_unicode(e) for e in row]) def fetchmany(self, size=None): if size is None: diff --git a/tests/regressiontests/backends/models.py b/tests/regressiontests/backends/models.py index db16d2c198..a041ab6b12 100644 --- a/tests/regressiontests/backends/models.py +++ b/tests/regressiontests/backends/models.py @@ -8,6 +8,13 @@ class Square(models.Model): def __unicode__(self): return "%s ** 2 == %s" % (self.root, self.square) +class Person(models.Model): + first_name = models.CharField(max_length=20) + last_name = models.CharField(max_length=20) + + def __unicode__(self): + return u'%s %s' % (self.first_name, self.last_name) + if connection.features.uses_case_insensitive_names: t_convert = lambda x: x.upper() else: @@ -32,4 +39,25 @@ __test__ = {'API_TESTS': """ >>> Square.objects.count() 11 +#6254: fetchone, fetchmany, fetchall return strings as unicode objects +>>> Person(first_name="John", last_name="Doe").save() +>>> Person(first_name="Jane", last_name="Doe").save() +>>> Person(first_name="Mary", last_name="Agnelline").save() +>>> Person(first_name="Peter", last_name="Parker").save() +>>> Person(first_name="Clark", last_name="Kent").save() +>>> opts2 = Person._meta +>>> f3, f4 = opts2.get_field('first_name'), opts2.get_field('last_name') +>>> query2 = ('SELECT %s, %s FROM %s ORDER BY %s' +... % (qn(f3.column), qn(f4.column), t_convert(opts2.db_table), +... qn(f3.column))) +>>> cursor.execute(query2) and None or None +>>> cursor.fetchone() +(u'Clark', u'Kent') + +>>> list(cursor.fetchmany(2)) +[(u'Jane', u'Doe'), (u'John', u'Doe')] + +>>> list(cursor.fetchall()) +[(u'Mary', u'Agnelline'), (u'Peter', u'Parker')] + """}