Do not use savepoints with PostgreSQL prior to 8.0.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8317 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
97da73a98c
commit
6bebb23318
|
@ -9,6 +9,7 @@ from django.db.backends.postgresql.client import DatabaseClient
|
|||
from django.db.backends.postgresql.creation import DatabaseCreation
|
||||
from django.db.backends.postgresql.introspection import DatabaseIntrospection
|
||||
from django.db.backends.postgresql.operations import DatabaseOperations
|
||||
from django.db.backends.postgresql.version import get_version
|
||||
from django.utils.encoding import smart_str, smart_unicode
|
||||
|
||||
try:
|
||||
|
@ -115,6 +116,12 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
|||
cursor = self.connection.cursor()
|
||||
if set_tz:
|
||||
cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
|
||||
if not hasattr(self, '_version'):
|
||||
version = get_version(cursor)
|
||||
self.__class__._version = version
|
||||
if version < (8, 0):
|
||||
# No savepoint support for earlier version of PostgreSQL.
|
||||
self.features.uses_savepoints = False
|
||||
cursor.execute("SET client_encoding to 'UNICODE'")
|
||||
cursor = UnicodeCursorWrapper(cursor, 'utf-8')
|
||||
return cursor
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
"""
|
||||
Extracts the version of the PostgreSQL server.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
VERSION_RE = re.compile(r'PostgreSQL (\d+)\.(\d+)\.')
|
||||
|
||||
def get_version(cursor):
|
||||
"""
|
||||
Returns a tuple representing the major and minor version number of the
|
||||
server. For example, (7, 4) or (8, 3).
|
||||
"""
|
||||
cursor.execute("SELECT version()")
|
||||
version = cursor.fetchone()[0]
|
||||
major, minor = VERSION_RE.search(version).groups()
|
||||
return int(major), int(minor)
|
||||
|
|
@ -8,6 +8,7 @@ from django.db.backends import *
|
|||
from django.db.backends.postgresql.operations import DatabaseOperations as PostgresqlDatabaseOperations
|
||||
from django.db.backends.postgresql.client import DatabaseClient
|
||||
from django.db.backends.postgresql.creation import DatabaseCreation
|
||||
from django.db.backends.postgresql.version import get_version
|
||||
from django.db.backends.postgresql_psycopg2.introspection import DatabaseIntrospection
|
||||
|
||||
from django.utils.safestring import SafeUnicode
|
||||
|
@ -86,4 +87,10 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
|||
cursor.tzinfo_factory = None
|
||||
if set_tz:
|
||||
cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
|
||||
if not hasattr(self, '_version'):
|
||||
version = get_version(cursor)
|
||||
self.__class__._version = version
|
||||
if version < (8, 0):
|
||||
# No savepoint support for earlier version of PostgreSQL.
|
||||
self.features.uses_savepoints = False
|
||||
return cursor
|
||||
|
|
Loading…
Reference in New Issue