Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed postgresql and postgresql_psycopg2 backends NOT to do a SELEC…

…T 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
  • Loading branch information...
commit 8b8a36c7d05f747685cd62e62776141029fef1dd 1 parent de2881f
@adrianholovaty adrianholovaty authored
View
3  django/db/backends/postgresql/base.py
@@ -102,9 +102,6 @@ def _cursor(self, settings):
cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
cursor.execute("SET client_encoding to 'UNICODE'")
cursor = UnicodeCursorWrapper(cursor, 'utf-8')
- if self.ops.postgres_version is None:
- cursor.execute("SELECT version()")
- self.ops.postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')]
return cursor
def typecast_string(s):
View
15 django/db/backends/postgresql/operations.py
@@ -4,8 +4,17 @@
# 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 @@ def sequence_reset_sql(self, style, model_list):
style.SQL_KEYWORD('IS NOT'),
style.SQL_KEYWORD('FROM'),
style.SQL_TABLE(f.m2m_db_table())))
- return output
+ return output
View
3  django/db/backends/postgresql_psycopg2/base.py
@@ -64,7 +64,4 @@ def _cursor(self, settings):
cursor.tzinfo_factory = None
if set_tz:
cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
- if self.ops.postgres_version is None:
- cursor.execute("SELECT version()")
- self.ops.postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')]
return cursor
Please sign in to comment.
Something went wrong with that request. Please try again.