Ticket #6433: postgres-versions.diff

File postgres-versions.diff, 1.4 KB (added by Jason Erickson, 17 years ago)

A new patch that works with RC/beta versions and Windows version strings

  • django/db/backends/postgresql/operations.py

     
    11from django.db.backends import BaseDatabaseOperations
     2import re
    23
    34# This DatabaseOperations class lives in here instead of base.py because it's
    45# used by both the 'postgresql' and 'postgresql_psycopg2' backends.
    56
     7# re string to match the numerical portion of the version numbers of PostgreSQL
     8#
     9server_version_re = re.compile(r'PostgreSQL (\d{1,2})\.(\d{1,2})\.?(\d{1,2})?')
     10
    611class DatabaseOperations(BaseDatabaseOperations):
    712    def __init__(self):
    813        self._postgres_version = None
     
    1217            from django.db import connection
    1318            cursor = connection.cursor()
    1419            cursor.execute("SELECT version()")
    15             self._postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')]
     20            version_string = cursor.fetchone()[0]
     21            m = server_version_re.match(version_string)
     22            if not m:
     23                raise Exception('Unable to determine PostgreSQL version from version() function string: %r' % version_string)
     24            self._postgres_version = [int(val) for val in m.groups() if val != None]
    1625        return self._postgres_version
    1726    postgres_version = property(_get_postgres_version)
    1827
Back to Top