Skip to content

Commit

Permalink
Fixed #4664 -- Forced the client character set encoding to UTF-8 for …
Browse files Browse the repository at this point in the history
…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.


git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5535 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Jun 25, 2007
1 parent 03ec642 commit dbb785c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 60 deletions.
16 changes: 4 additions & 12 deletions django/db/backends/postgresql/base.py
Expand Up @@ -6,7 +6,6 @@

from django.utils.encoding import smart_str, smart_unicode
from django.db.backends import util
from django.db.backends.postgresql.encodings import ENCODING_MAP
try:
import psycopg as Database
except ImportError, e:
Expand Down Expand Up @@ -64,7 +63,6 @@ def __getattr__(self, attr):
return getattr(self.cursor, attr)

postgres_version = None
client_encoding = None

class DatabaseWrapper(local):
def __init__(self, **kwargs):
Expand Down Expand Up @@ -94,15 +92,8 @@ def cursor(self):
cursor = self.connection.cursor()
if set_tz:
cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
cursor.execute("SHOW client_encoding")
encoding = ENCODING_MAP[cursor.fetchone()[0]]
cursor = UnicodeCursorWrapper(cursor, encoding)
global client_encoding
if not client_encoding:
# We assume the client encoding isn't going to change for random
# reasons.
Database.register_type(Database.new_type(Database.types[1043].values, 'STRING', typecast_string))
client_encoding = encoding
cursor.execute("SET client_encoding to 'UNICODE'")
cursor = UnicodeCursorWrapper(cursor, 'utf-8')
global postgres_version
if not postgres_version:
cursor.execute("SELECT version()")
Expand Down Expand Up @@ -289,7 +280,7 @@ def typecast_string(s):
"""
if not s:
return s
return smart_unicode(s, client_encoding)
return smart_unicode(s)

# Register these custom typecasts, because Django expects dates/times to be
# in Python's native (standard-library) datetime/time format, whereas psycopg
Expand All @@ -302,6 +293,7 @@ def typecast_string(s):
Database.register_type(Database.new_type((1114,1184), "TIMESTAMP", util.typecast_timestamp))
Database.register_type(Database.new_type((16,), "BOOLEAN", util.typecast_boolean))
Database.register_type(Database.new_type((1700,), "NUMERIC", util.typecast_decimal))
Database.register_type(Database.new_type(Database.types[1043].values, 'STRING', typecast_string))

OPERATOR_MAPPING = {
'exact': '= %s',
Expand Down
48 changes: 0 additions & 48 deletions django/db/backends/postgresql/encodings.py

This file was deleted.

0 comments on commit dbb785c

Please sign in to comment.