summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/operations.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-08-25 19:24:47 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-08-25 19:24:47 +0000
commit8b8a36c7d05f747685cd62e62776141029fef1dd (patch)
tree4adb8ce36bd6a24fbaaacb32a81569586697a32b /django/db/backends/postgresql/operations.py
parentde2881f9f22bfe621fe3c00fd1fdb7c0a905df0f (diff)
downloaddjango-8b8a36c7d05f747685cd62e62776141029fef1dd.tar.gz
Changed postgresql and postgresql_psycopg2 backends NOT to do a SELECT version() for every connection, which was ludicrous. Now the version is only retrieved if it needs to be, via a lazy loader.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6012 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/postgresql/operations.py')
-rw-r--r--django/db/backends/postgresql/operations.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index 4c32c4eeb1..9f36596ace 100644
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -4,8 +4,17 @@ from django.db.backends import BaseDatabaseOperations
# used by both the 'postgresql' and 'postgresql_psycopg2' backends.
class DatabaseOperations(BaseDatabaseOperations):
- def __init__(self, postgres_version=None):
- self.postgres_version = postgres_version
+ def __init__(self):
+ self._postgres_version = None
+
+ def _get_postgres_version(self):
+ if self._postgres_version is None:
+ from django.db import connection
+ cursor = connection.cursor()
+ cursor.execute("SELECT version()")
+ self._postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')]
+ return self._postgres_version
+ postgres_version = property(_get_postgres_version)
def date_extract_sql(self, lookup_type, field_name):
# http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
@@ -92,4 +101,4 @@ class DatabaseOperations(BaseDatabaseOperations):
style.SQL_KEYWORD('IS NOT'),
style.SQL_KEYWORD('FROM'),
style.SQL_TABLE(f.m2m_db_table())))
- return output \ No newline at end of file
+ return output