Django

Code

Changeset 5535

Show
Ignore:
Timestamp:
06/25/07 09:40:08 (1 year ago)
Author:
mtredinnick
Message:

Fixed #4664 -- Forced the client character set encoding to UTF-8 for PostgreSQL
(via the psycopg backend). The previous version was causing problems on some
setups, particularly PostgreSQL 7.x. Current code should work with 7.x and 8.x,
no matter what the default client encoding is.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/unicode/django/db/backends/postgresql/base.py

    r5531 r5535  
    77from django.utils.encoding import smart_str, smart_unicode 
    88from django.db.backends import util 
    9 from django.db.backends.postgresql.encodings import ENCODING_MAP 
    109try: 
    1110    import psycopg as Database 
     
    6564 
    6665postgres_version = None 
    67 client_encoding = None 
    6866 
    6967class DatabaseWrapper(local): 
     
    9593        if set_tz: 
    9694            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) 
    97         cursor.execute("SHOW client_encoding") 
    98         encoding = ENCODING_MAP[cursor.fetchone()[0]] 
    99         cursor = UnicodeCursorWrapper(cursor, encoding) 
    100         global client_encoding 
    101         if not client_encoding: 
    102             # We assume the client encoding isn't going to change for random 
    103             # reasons. 
    104             Database.register_type(Database.new_type(Database.types[1043].values, 'STRING', typecast_string)) 
    105             client_encoding = encoding 
     95        cursor.execute("SET client_encoding to 'UNICODE'") 
     96        cursor = UnicodeCursorWrapper(cursor, 'utf-8') 
    10697        global postgres_version 
    10798        if not postgres_version: 
     
    290281    if not s: 
    291282        return s 
    292     return smart_unicode(s, client_encoding
     283    return smart_unicode(s
    293284 
    294285# Register these custom typecasts, because Django expects dates/times to be 
     
    303294Database.register_type(Database.new_type((16,), "BOOLEAN", util.typecast_boolean)) 
    304295Database.register_type(Database.new_type((1700,), "NUMERIC", util.typecast_decimal)) 
     296Database.register_type(Database.new_type(Database.types[1043].values, 'STRING', typecast_string)) 
    305297 
    306298OPERATOR_MAPPING = {