summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/base.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-08-19 21:30:57 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-08-19 21:30:57 +0000
commit7c41b19c8a11e4ce46608f25e097118ddb1b3f5e (patch)
tree9945844469fe5224a4589001b5ce08a41191d1f5 /django/db/backends/postgresql/base.py
parent77a9b0cb1d0da2a4c9cee60c2d305661b49d17da (diff)
Refactored all database backends to inherit from a common base class to remove quite a bit of duplicated code. Thanks for the patch, Brian Harring. Refs #5106
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5949 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/postgresql/base.py')
-rw-r--r--django/db/backends/postgresql/base.py34
1 files changed, 3 insertions, 31 deletions
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
index 9d0967fa2b..0238ce8c57 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -5,7 +5,7 @@ Requires psycopg 1: http://initd.org/projects/psycopg1
"""
from django.utils.encoding import smart_str, smart_unicode
-from django.db.backends import util
+from django.db.backends import BaseDatabaseWrapper, util
try:
import psycopg as Database
except ImportError, e:
@@ -15,13 +15,6 @@ except ImportError, e:
DatabaseError = Database.DatabaseError
IntegrityError = Database.IntegrityError
-try:
- # Only exists in Python 2.4+
- from threading import local
-except ImportError:
- # Import copy of _thread_local.py from Python 2.4
- from django.utils._threading_local import local
-
class UnicodeCursorWrapper(object):
"""
A thin wrapper around psycopg cursors that allows them to accept Unicode
@@ -64,14 +57,8 @@ class UnicodeCursorWrapper(object):
postgres_version = None
-class DatabaseWrapper(local):
- def __init__(self, **kwargs):
- self.connection = None
- self.queries = []
- self.options = kwargs
-
- def cursor(self):
- from django.conf import settings
+class DatabaseWrapper(BaseDatabaseWrapper):
+ def _cursor(self, settings):
set_tz = False
if self.connection is None:
set_tz = True
@@ -98,23 +85,8 @@ class DatabaseWrapper(local):
if not postgres_version:
cursor.execute("SELECT version()")
postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')]
- if settings.DEBUG:
- return util.CursorDebugWrapper(cursor, self)
return cursor
- def _commit(self):
- if self.connection is not None:
- return self.connection.commit()
-
- def _rollback(self):
- if self.connection is not None:
- return self.connection.rollback()
-
- def close(self):
- if self.connection is not None:
- self.connection.close()
- self.connection = None
-
allows_group_by_ordinal = True
allows_unique_and_pk = True
autoindexes_primary_keys = True