Ticket #1051: ticket_1051_rev6098.diff

File ticket_1051_rev6098.diff, 3.7 KB (added by roppert <robert@…>, 8 years ago)

Patch to apply cleanly against trunk (rev 6098)

  • django/db/backends/postgresql/base.py

     
    8181
    8282    def _cursor(self, settings):
    8383        set_tz = False
     84        set_path = False
    8485        if self.connection is None:
    8586            set_tz = True
    8687            if settings.DATABASE_NAME == '':
     
    9596                conn_string += " host=%s" % settings.DATABASE_HOST
    9697            if settings.DATABASE_PORT:
    9798                conn_string += " port=%s" % settings.DATABASE_PORT
     99            if settings.DATABASE_SCHEMAS:
     100                set_path = True
    98101            self.connection = Database.connect(conn_string, **self.options)
    99102            self.connection.set_isolation_level(1) # make transactions transparent to all cursors
    100103        cursor = self.connection.cursor()
    101104        if set_tz:
    102105            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
     106        if set_path:
     107            cursor.execute("SET search_path TO %s", settings.DATABASE_SCHEMAS)
    103108        cursor.execute("SET client_encoding to 'UNICODE'")
    104109        cursor = UnicodeCursorWrapper(cursor, 'utf-8')
    105110        return cursor
  • django/db/backends/postgresql_psycopg2/base.py

     
    4343
    4444    def _cursor(self, settings):
    4545        set_tz = False
     46        set_path = False
    4647        if self.connection is None:
    4748            set_tz = True
    4849            if settings.DATABASE_NAME == '':
     
    5758                conn_string += " host=%s" % settings.DATABASE_HOST
    5859            if settings.DATABASE_PORT:
    5960                conn_string += " port=%s" % settings.DATABASE_PORT
     61            if settings.DATABASE_SCHEMAS:
     62                set_path = True
    6063            self.connection = Database.connect(conn_string, **self.options)
    6164            self.connection.set_isolation_level(1) # make transactions transparent to all cursors
    6265            self.connection.set_client_encoding('UTF8')
     
    6467        cursor.tzinfo_factory = None
    6568        if set_tz:
    6669            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
     70        if set_path:
     71            cursor.execute("SET search_path TO %s", settings.DATABASE_SCHEMAS)
    6772        return cursor
  • django/conf/project_template/settings.py

     
    1111
    1212DATABASE_ENGINE = ''           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    1313DATABASE_NAME = ''             # Or path to database file if using sqlite3.
     14DATABASE_SCHEMAS = ''          # Only used with postgresq to support multiple schemas
    1415DATABASE_USER = ''             # Not used with sqlite3.
    1516DATABASE_PASSWORD = ''         # Not used with sqlite3.
    1617DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
  • docs/settings.txt

     
    316316
    317317The username to use when connecting to the database. Not used with SQLite.
    318318
     319DATABASE_SCHEMAS
     320----------------
     321
     322Default: ``''`` (Empty string)
     323
     324On databases supporting Schemas, like PostgreSQL, the search_path will be
     325set to the value of this setting which is, by default, ``public``.
     326
     327Please, note that currently the only backend which schema support is PostgreSQL.
     328
    319329DATE_FORMAT
    320330-----------
    321331
Back to Top