summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/version.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-05-10 09:22:06 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-05-10 09:22:06 +0000
commitb97178f7ec311da7c885a122a2ccc1036bacf0d3 (patch)
tree4ee3f4409bec165fe2de50b6e580f9c5610f137b /django/db/backends/postgresql/version.py
parent5663258de13975e28406233328a9e51c8bc1b768 (diff)
downloaddjango-b97178f7ec311da7c885a122a2ccc1036bacf0d3.tar.gz
Fixed #10842 -- Corrected parsing of version numbers for PostgreSQL 8.4beta series. Thanks to hgdeoro for the report and fix.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10730 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/postgresql/version.py')
-rw-r--r--django/db/backends/postgresql/version.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/django/db/backends/postgresql/version.py b/django/db/backends/postgresql/version.py
index ed2ad9e441..8fd773e59b 100644
--- a/django/db/backends/postgresql/version.py
+++ b/django/db/backends/postgresql/version.py
@@ -4,20 +4,28 @@ Extracts the version of the PostgreSQL server.
import re
-# This reg-exp is intentionally fairly flexible here. Require only the major
-# and minor version numbers, but need to be able to handle standard stuff like:
+# This reg-exp is intentionally fairly flexible here.
+# Needs to be able to handle stuff like:
# PostgreSQL 8.3.6
# EnterpriseDB 8.3
# PostgreSQL 8.3 beta4
-VERSION_RE = re.compile(r'\S+ (\d+)\.(\d+)')
+# PostgreSQL 8.4beta1
+VERSION_RE = re.compile(r'\S+ (\d+)\.(\d+)\.?(\d+)?')
+
+def _parse_version(text):
+ "Internal parsing method. Factored out for testing purposes."
+ major, major2, minor = VERSION_RE.search(text).groups()
+ try:
+ return int(major), int(major2), int(minor)
+ except (ValueError, TypeError):
+ return int(major), int(major2), None
def get_version(cursor):
"""
- Returns a tuple representing the major and minor version number of the
- server. For example, (7, 4) or (8, 3).
+ Returns a tuple representing the major, minor and revision number of the
+ server. For example, (7, 4, 1) or (8, 3, 4). The revision number will be
+ None in the case of initial releases (e.g., 'PostgreSQL 8.3') or in the
+ case of beta and prereleases ('PostgreSQL 8.4beta1').
"""
cursor.execute("SELECT version()")
- version = cursor.fetchone()[0]
- major, minor = VERSION_RE.search(version).groups()
- return int(major), int(minor)
-
+ return _parse_version(cursor.fetchone()[0])