Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 6bebb23318c5a2195a89a7154118cfc5ea19bba7 1 parent 97da73a
@malcolmt malcolmt authored
View
7 django/db/backends/postgresql/base.py
@@ -9,6 +9,7 @@
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 @@ def _cursor(self, settings):
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
View
18 django/db/backends/postgresql/version.py
@@ -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)
+
View
7 django/db/backends/postgresql_psycopg2/base.py
@@ -8,6 +8,7 @@
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 @@ def _cursor(self, settings):
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
Please sign in to comment.
Something went wrong with that request. Please try again.