Exemplo n.º 1
0
    def _set_oracle_default_schema(self, cursor):
        '''
        this is somewhat the equivalent of postgresql_backend ``_set_pg_search_path``

        .. note::

            ORACLE does not allow a fallback to the current USER schema like in
            PostgreSQL with the ``public`` schema
        '''
        if self.schema_name is None:
            if settings.DEBUG:
                full_info = " Choices are: %s." \
                            % ', '.join(settings.SCHEMATA_DOMAINS.keys())
            else:
                full_info = ""
            raise ImproperlyConfigured(
                "Database schema not set (you can pick "
                "one of the supported domains by setting "
                "then DJANGO_SCHEMATA_DOMAIN environment "
                "variable.%s)" % full_info)

        base_sql_command = 'ALTER SESSION SET current_schema = '

        if self.schema_name == '':
            # set the current_schema to a current USER
            cursor.execute("""begin
                    EXECUTE IMMEDIATE '%s' || USER; 
                    end;
                    /""" % base_sql_command)
        else:
            _check_identifier(self.schema_name)
            sql_command = base_sql_command + self.schema_name
            cursor.execute(sql_command)
Exemplo n.º 2
0
    def _set_oracle_default_schema(self, cursor):
        '''
        this is somewhat the equivalent of postgresql_backend ``_set_pg_search_path``

        .. note::

            ORACLE does not allow a fallback to the current USER schema like in
            PostgreSQL with the ``public`` schema
        '''
        if self.schema_name is None:
            if settings.DEBUG:
                full_info = " Choices are: %s." \
                            % ', '.join(settings.SCHEMATA_DOMAINS.keys())
            else:
                full_info = ""
            raise ImproperlyConfigured("Database schema not set (you can pick "
                                       "one of the supported domains by setting "
                                       "then DJANGO_SCHEMATA_DOMAIN environment "
                                       "variable.%s)" % full_info)

        base_sql_command = 'ALTER SESSION SET current_schema = '

        if self.schema_name == '':
            # set the current_schema to a current USER
            cursor.execute("""begin
                    EXECUTE IMMEDIATE '%s' || USER; 
                    end;
                    /""" % base_sql_command)
        else:
            _check_identifier(self.schema_name)
            sql_command = base_sql_command + self.schema_name
            cursor.execute(sql_command)
Exemplo n.º 3
0
    def create_schemata(self):
        """
        Go through settings.SCHEMATA_DOMAINS and create all schemata that
        do not already exist in the database. 
        """
        # operate in the public schema
        connection.set_schemata_off()
        cursor = connection.cursor()
        cursor.execute('SELECT schema_name FROM information_schema.schemata')
        existing_schemata = [row[0] for row in cursor.fetchall()]

        for sd in settings.SCHEMATA_DOMAINS.values():
            schema_name = str(sd['schema_name'])
            _check_identifier(schema_name)

            if schema_name not in existing_schemata:
                sql = 'CREATE SCHEMA %s' % schema_name
                print sql
                cursor.execute(sql)
                transaction.commit_unless_managed()
Exemplo n.º 4
0
    def create_schemata(self):
        """
        Go through settings.SCHEMATA_DOMAINS and create all schemata that
        do not already exist in the database. 
        """
        # operate in the public schema
        connection.set_schemata_off()
        cursor = connection.cursor()
        cursor.execute('SELECT schema_name FROM information_schema.schemata')
        existing_schemata = [ row[0] for row in cursor.fetchall() ]

        for sd in settings.SCHEMATA_DOMAINS.values():
            schema_name = str(sd['schema_name'])
            _check_identifier(schema_name)
        
            if schema_name not in existing_schemata:
                sql = 'CREATE SCHEMA %s' % schema_name
                print sql
                cursor.execute(sql)
                transaction.commit_unless_managed()
Exemplo n.º 5
0
    def _set_pg_search_path(self, cursor):
        """
        Actual search_path modification for the cursor. Database will
        search schemata from left to right when looking for the object
        (table, index, sequence, etc.).
        """
        if self.schema_name is None:
            if settings.DEBUG:
                full_info = " Choices are: %s." \
                            % ', '.join(settings.SCHEMATA_DOMAINS.keys())
            else:
                full_info = ""
            raise ImproperlyConfigured("Database schema not set (you can pick "
                                       "one of the supported domains by setting "
                                       "then DJANGO_SCHEMATA_DOMAIN environment "
                                       "variable.%s)" % full_info)

        _check_identifier(self.schema_name)
        if self.schema_name == 'public':
            cursor.execute('SET search_path = public')
        else:
            cursor.execute('SET search_path = %s, public', [self.schema_name])
Exemplo n.º 6
0
    def _set_pg_search_path(self, cursor):
        """
        Actual search_path modification for the cursor. Database will
        search schemata from left to right when looking for the object
        (table, index, sequence, etc.).
        """
        if self.schema_name is None:
            if settings.DEBUG:
                full_info = " Choices are: %s." \
                            % ', '.join(settings.SCHEMATA_DOMAINS.keys())
            else:
                full_info = ""
            raise ImproperlyConfigured(
                "Database schema not set (you can pick "
                "one of the supported domains by setting "
                "then DJANGO_SCHEMATA_DOMAIN environment "
                "variable.%s)" % full_info)

        _check_identifier(self.schema_name)
        if self.schema_name == 'public':
            cursor.execute('SET search_path = public')
        else:
            cursor.execute('SET search_path = %s, public', [self.schema_name])