Ticket #3492: postgresql_unicode_extra_fix.patch

File postgresql_unicode_extra_fix.patch, 1.8 KB (added by Chris.Wesseling@…, 18 years ago)

Fixes a bug when using unicode in extra query

  • django/db/backends/postgresql/base.py

     
    4040        self.charset = charset
    4141
    4242    def execute(self, sql, params=()):
    43         return self.cursor.execute(sql, [smart_basestring(p, self.charset) for p in params])
     43        return self.cursor.execute(smart_basestring(sql, self.charset), [smart_basestring(p, self.charset) for p in params])
    4444
    4545    def executemany(self, sql, param_list):
    4646        new_param_list = [tuple([smart_basestring(p, self.charset) for p in params]) for params in param_list]
    47         return self.cursor.executemany(sql, new_param_list)
     47        return self.cursor.executemany(smart_basestring(sql, self.charset), new_param_list)
    4848
    4949    def __getattr__(self, attr):
    5050        if self.__dict__.has_key(attr):
  • tests/modeltests/many_to_one/models.py

     
    154154>>> Article.objects.filter(reporter__first_name__exact='John').extra(where=["many_to_one_article__reporter.last_name='Smith'"])
    155155[<Article: John's second story>, <Article: This is a test>]
    156156
     157# And should work fine with the unicode that comes out of newforms.Form.clean_data
     158>>> Article.objects.filter(reporter__first_name__exact='John').extra(where=["many_to_one_article__reporter.last_name='%s'" % u'Smith'])
     159[<Article: John's second story>, <Article: This is a test>]
     160
    157161# Find all Articles for the Reporter whose ID is 1.
    158162# Use direct ID check, pk check, and object comparison
    159163>>> Article.objects.filter(reporter__id__exact=1)
Back to Top