diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-12-22 15:18:51 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-12-22 15:18:51 +0000 |
| commit | ff60c5f9de3e8690d1e86f3e9e3f7248a15397c8 (patch) | |
| tree | a4cb0ebdd55fcaf8c8855231b6ad3e1a7bf45bee /django/db/backends/postgresql | |
| parent | 7ef212af149540aa2da577a960d0d87029fd1514 (diff) | |
Fixed #1142 -- Added multiple database support.
This monster of a patch is the result of Alex Gaynor's 2009 Google Summer of Code project.
Congratulations to Alex for a job well done.
Big thanks also go to:
* Justin Bronn for keeping GIS in line with the changes,
* Karen Tracey and Jani Tiainen for their help testing Oracle support
* Brett Hoerner, Jon Loyens, and Craig Kimmerer for their feedback.
* Malcolm Treddinick for his guidance during the GSoC submission process.
* Simon Willison for driving the original design process
* Cal Henderson for complaining about ponies he wanted.
... and everyone else too numerous to mention that helped to bring this feature into fruition.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11952 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/postgresql')
| -rw-r--r-- | django/db/backends/postgresql/base.py | 30 | ||||
| -rw-r--r-- | django/db/backends/postgresql/client.py | 14 | ||||
| -rw-r--r-- | django/db/backends/postgresql/creation.py | 7 | ||||
| -rw-r--r-- | django/db/backends/postgresql/operations.py | 7 |
4 files changed, 29 insertions, 29 deletions
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index 19d5ea74d8..119df9f171 100644 --- a/django/db/backends/postgresql/base.py +++ b/django/db/backends/postgresql/base.py @@ -90,30 +90,30 @@ class DatabaseWrapper(BaseDatabaseWrapper): super(DatabaseWrapper, self).__init__(*args, **kwargs) self.features = DatabaseFeatures() - self.ops = DatabaseOperations() + self.ops = DatabaseOperations(self) self.client = DatabaseClient(self) self.creation = DatabaseCreation(self) self.introspection = DatabaseIntrospection(self) - self.validation = BaseDatabaseValidation() + self.validation = BaseDatabaseValidation(self) def _cursor(self): set_tz = False settings_dict = self.settings_dict if self.connection is None: set_tz = True - if settings_dict['DATABASE_NAME'] == '': + if settings_dict['NAME'] == '': from django.core.exceptions import ImproperlyConfigured - raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.") - conn_string = "dbname=%s" % settings_dict['DATABASE_NAME'] - if settings_dict['DATABASE_USER']: - conn_string = "user=%s %s" % (settings_dict['DATABASE_USER'], conn_string) - if settings_dict['DATABASE_PASSWORD']: - conn_string += " password='%s'" % settings_dict['DATABASE_PASSWORD'] - if settings_dict['DATABASE_HOST']: - conn_string += " host=%s" % settings_dict['DATABASE_HOST'] - if settings_dict['DATABASE_PORT']: - conn_string += " port=%s" % settings_dict['DATABASE_PORT'] - self.connection = Database.connect(conn_string, **settings_dict['DATABASE_OPTIONS']) + raise ImproperlyConfigured("You need to specify NAME in your Django settings file.") + conn_string = "dbname=%s" % settings_dict['NAME'] + if settings_dict['USER']: + conn_string = "user=%s %s" % (settings_dict['USER'], conn_string) + if settings_dict['PASSWORD']: + conn_string += " password='%s'" % settings_dict['PASSWORD'] + if settings_dict['HOST']: + conn_string += " host=%s" % settings_dict['HOST'] + if settings_dict['PORT']: + conn_string += " port=%s" % settings_dict['PORT'] + self.connection = Database.connect(conn_string, **settings_dict['OPTIONS']) self.connection.set_isolation_level(1) # make transactions transparent to all cursors connection_created.send(sender=self.__class__) cursor = self.connection.cursor() @@ -142,7 +142,7 @@ def typecast_string(s): try: Database.register_type(Database.new_type((1082,), "DATE", util.typecast_date)) except AttributeError: - raise Exception("You appear to be using psycopg version 2. Set your DATABASE_ENGINE to 'postgresql_psycopg2' instead of 'postgresql'.") + raise Exception("You appear to be using psycopg version 2. Set your DATABASES.ENGINE to 'postgresql_psycopg2' instead of 'postgresql'.") Database.register_type(Database.new_type((1083,1266), "TIME", util.typecast_time)) Database.register_type(Database.new_type((1114,1184), "TIMESTAMP", util.typecast_timestamp)) Database.register_type(Database.new_type((16,), "BOOLEAN", util.typecast_boolean)) diff --git a/django/db/backends/postgresql/client.py b/django/db/backends/postgresql/client.py index 13273b9fb5..a5c02969ea 100644 --- a/django/db/backends/postgresql/client.py +++ b/django/db/backends/postgresql/client.py @@ -9,13 +9,13 @@ class DatabaseClient(BaseDatabaseClient): def runshell(self): settings_dict = self.connection.settings_dict args = [self.executable_name] - if settings_dict['DATABASE_USER']: - args += ["-U", settings_dict['DATABASE_USER']] - if settings_dict['DATABASE_HOST']: - args.extend(["-h", settings_dict['DATABASE_HOST']]) - if settings_dict['DATABASE_PORT']: - args.extend(["-p", str(settings_dict['DATABASE_PORT'])]) - args += [settings_dict['DATABASE_NAME']] + if settings_dict['USER']: + args += ["-U", settings_dict['USER']] + if settings_dict['HOST']: + args.extend(["-h", settings_dict['HOST']]) + if settings_dict['PORT']: + args.extend(["-p", str(settings_dict['PORT'])]) + args += [settings_dict['NAME']] if os.name == 'nt': sys.exit(os.system(" ".join(args))) else: diff --git a/django/db/backends/postgresql/creation.py b/django/db/backends/postgresql/creation.py index be7f49482b..af26d0b78f 100644 --- a/django/db/backends/postgresql/creation.py +++ b/django/db/backends/postgresql/creation.py @@ -1,4 +1,3 @@ -from django.conf import settings from django.db.backends.creation import BaseDatabaseCreation class DatabaseCreation(BaseDatabaseCreation): @@ -31,9 +30,9 @@ class DatabaseCreation(BaseDatabaseCreation): } def sql_table_creation_suffix(self): - assert settings.TEST_DATABASE_COLLATION is None, "PostgreSQL does not support collation setting at database creation time." - if settings.TEST_DATABASE_CHARSET: - return "WITH ENCODING '%s'" % settings.TEST_DATABASE_CHARSET + assert self.connection.settings_dict['TEST_COLLATION'] is None, "PostgreSQL does not support collation setting at database creation time." + if self.connection.settings_dict['TEST_CHARSET']: + return "WITH ENCODING '%s'" % self.connection.settings_dict['TEST_CHARSET'] return '' def sql_indexes_for_field(self, model, f, style): diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py index 331156ee11..f51743646d 100644 --- a/django/db/backends/postgresql/operations.py +++ b/django/db/backends/postgresql/operations.py @@ -6,14 +6,15 @@ from django.db.backends import BaseDatabaseOperations # used by both the 'postgresql' and 'postgresql_psycopg2' backends. class DatabaseOperations(BaseDatabaseOperations): - def __init__(self): + def __init__(self, connection): + super(DatabaseOperations, self).__init__() self._postgres_version = None + self.connection = connection def _get_postgres_version(self): if self._postgres_version is None: - from django.db import connection from django.db.backends.postgresql.version import get_version - cursor = connection.cursor() + cursor = self.connection.cursor() self._postgres_version = get_version(cursor) return self._postgres_version postgres_version = property(_get_postgres_version) |
