diff options
author | ttt | 2017-05-13 00:29:47 +0530 |
---|---|---|
committer | ttt | 2017-05-13 00:29:47 +0530 |
commit | abf599be33b383a6a5baf9493093b2126a622ac8 (patch) | |
tree | 4c5ab6e0d935d5e65fabcf0258e4a00dd20a5afa /lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/version.py | |
download | SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.gz SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.bz2 SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.zip |
added all server files
Diffstat (limited to 'lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/version.py')
-rw-r--r-- | lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/version.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/version.py b/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/version.py new file mode 100644 index 0000000..8ef5167 --- /dev/null +++ b/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/version.py @@ -0,0 +1,43 @@ +""" +Extracts the version of the PostgreSQL server. +""" + +import re + +# 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 +# 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) * 10000 + int(major2) * 100 + int(minor) + except (ValueError, TypeError): + return int(major) * 10000 + int(major2) * 100 + +def get_version(connection): + """ + Returns an integer representing the major, minor and revision number of the + server. Format is the one used for the return value of libpq + PQServerVersion()/``server_version`` connection attribute (available in + newer psycopg2 versions.) + + For example, 80304 for 8.3.4. The last two digits will be 00 in the case of + releases (e.g., 80400 for 'PostgreSQL 8.4') or in the case of beta and + prereleases (e.g. 90100 for 'PostgreSQL 9.1beta2'). + + PQServerVersion()/``server_version`` doesn't execute a query so try that + first, then fallback to a ``SELECT version()`` query. + """ + if hasattr(connection, 'server_version'): + return connection.server_version + else: + cursor = connection.cursor() + cursor.execute("SELECT version()") + return _parse_version(cursor.fetchone()[0]) |