summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/base.py
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-06-25 14:40:08 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-06-25 14:40:08 +0000
commitdbb785c0b4da1103368cc2d1e368d91063117ec6 (patch)
treec5e3122c6b1e284a560104b4a8050f120006b19a /django/db/backends/postgresql/base.py
parent03ec6423c4850b141730333be4898858e0d45068 (diff)
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. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5535 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/postgresql/base.py')
-rw-r--r--django/db/backends/postgresql/base.py16
1 files changed, 4 insertions, 12 deletions
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
index ea19f65839..e2051beaa2 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -6,7 +6,6 @@ Requires psycopg 1: http://initd.org/projects/psycopg1
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:
@@ -64,7 +63,6 @@ class UnicodeCursorWrapper(object):
return getattr(self.cursor, attr)
postgres_version = None
-client_encoding = None
class DatabaseWrapper(local):
def __init__(self, **kwargs):
@@ -94,15 +92,8 @@ class DatabaseWrapper(local):
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()")
@@ -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
@@ -302,6 +293,7 @@ Database.register_type(Database.new_type((1083,1266), "TIME", util.typecast_time
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',