當前位置: 首頁>>代碼示例>>Python>>正文


Python creation.BaseDatabaseCreation類代碼示例

本文整理匯總了Python中django.db.backends.creation.BaseDatabaseCreation的典型用法代碼示例。如果您正苦於以下問題:Python BaseDatabaseCreation類的具體用法?Python BaseDatabaseCreation怎麽用?Python BaseDatabaseCreation使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了BaseDatabaseCreation類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

    def __init__(self):

        try:
            # Add missing index on object_id on AccessControl table
            creation = BaseDatabaseCreation(connection)
            sql = creation.sql_indexes_for_field(
                AccessControl,
                AccessControl._meta.get_field('object_id'),
                no_style(),
            )
            cursor = connection.cursor()
            for s in sql:
                cursor.execute(s)
        except:
            pass

        try:
            # Remove IP based group members
            for group in ExtendedGroup.objects.filter(type=IP_BASED_GROUP):
                group.user_set.all().delete()
        except:
            pass

        # Only need to run once
        raise MiddlewareNotUsed
開發者ID:hanleybrand,項目名稱:mdid_dj16,代碼行數:25,代碼來源:middleware.py

示例2: __init__

    def __init__(self):

        try:
            # Add missing index on object_id on AccessControl table
            creation = BaseDatabaseCreation(connection)
            sql = creation.sql_indexes_for_field(
                AccessControl,
                AccessControl._meta.get_field('object_id'),
                no_style(),
            )
            cursor = connection.cursor()
            for s in sql:
                logging.debug("running query %s" % s)
                cursor.execute(s)
                logging.debug("done")
        except:
            logging.exception("error running query")
            #pass

        try:
            # Remove IP based group members
            for group in ExtendedGroup.objects.filter(type=IP_BASED_GROUP):
                logging.debug("deleting users from group %s" % group.id)
                group.user_set.clear()
                logging.debug("done")
        except:
            logging.exception("error deleting users")
            #pass

        # Only need to run once
        raise MiddlewareNotUsed
開發者ID:WMInfoTech,項目名稱:rooibos,代碼行數:31,代碼來源:middleware.py

示例3: run_sql

def run_sql(model):
	#Runs the SQL to create the table and create indices
	
	style=color.no_style()
	cursor=connection.cursor()
	obj=BaseDatabaseCreation(connection)
	statements,pending = obj.sql_create_model(model,style)
	index_queries=obj.sql_indexes_for_model(model,style)
	for sql in statements:
		cursor.execute(sql)
	for query in index_queries:
		cursor.execute(query)	
開發者ID:radhikashrotre,項目名稱:Django-Custom-Forms,代碼行數:12,代碼來源:useful.py

示例4: _create_index_name

 def _create_index_name(self, model, column_names, suffix=""):
     """
     Generates a unique name for an index/unique constraint.
     """
     # If there is just one column in the index, use a default algorithm from Django
     if len(column_names) == 1 and not suffix:
         return truncate_name(
             '%s_%s' % (model._meta.db_table, BaseDatabaseCreation._digest(column_names[0])),
             self.connection.ops.max_name_length()
         )
     # Else generate the name for the index using a different algorithm
     table_name = model._meta.db_table.replace('"', '').replace('.', '_')
     index_unique_name = '_%x' % abs(hash((table_name, ','.join(column_names))))
     max_length = self.connection.ops.max_name_length() or 200
     # If the index name is too long, truncate it
     index_name = ('%s_%s%s%s' % (
         table_name, column_names[0], index_unique_name, suffix,
     )).replace('"', '').replace('.', '_')
     if len(index_name) > max_length:
         part = ('_%s%s%s' % (column_names[0], index_unique_name, suffix))
         index_name = '%s%s' % (table_name[:(max_length - len(part))], part)
     # It shouldn't start with an underscore (Oracle hates this)
     if index_name[0] == "_":
         index_name = index_name[1:]
     # If it's STILL too long, just hash it down
     if len(index_name) > max_length:
         index_name = hashlib.md5(force_bytes(index_name)).hexdigest()[:max_length]
     # It can't start with a number on Oracle, so prepend D if we need to
     if index_name[0].isdigit():
         index_name = "D%s" % index_name[:-1]
     return index_name
開發者ID:BardRobort,項目名稱:django,代碼行數:31,代碼來源:schema.py

示例5: _digest

 def _digest(self, *args):
     """
     Use django.db.backends.creation.BaseDatabaseCreation._digest
     to create index name in Django style. An evil hack :(
     """
     if not hasattr(self, '_django_db_creation'):
         self._django_db_creation = BaseDatabaseCreation(self._get_connection())
     return self._django_db_creation._digest(*args)
開發者ID:AMHZR,項目名稱:appartments,代碼行數:8,代碼來源:generic.py

示例6: __init__

    def __init__(self):

        try:
            # Add missing index on object_id on AccessControl table
            creation = BaseDatabaseCreation(connection)
            sql = creation.sql_indexes_for_field(
                AccessControl,
                AccessControl._meta.get_field('object_id'),
                no_style(),
            )
            cursor = connection.cursor()
            for s in sql:
                cursor.execute(s)
        except:
            pass

        # Only need to run once
        raise MiddlewareNotUsed
開發者ID:Blanko2,項目名稱:vic-mdid,代碼行數:18,代碼來源:middleware.py

示例7: DatabaseOperations


#.........這裏部分代碼省略.........
        """
        if self.dry_run:
            if self.debug:
                print('   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry')
            return  # We can't look at the DB to get the constraints
        constraints = self._find_foreign_constraints(table_name, column)
        if not constraints:
            raise ValueError("Cannot find a FOREIGN KEY constraint on table %s, column %s" % (table_name, column))
        for constraint_name in constraints:
            self.execute(self.delete_foreign_key_sql % {
                "table": self.quote_name(table_name),
                "constraint": self.quote_name(constraint_name),
            })

    drop_foreign_key = alias('delete_foreign_key')

    def _find_foreign_constraints(self, table_name, column_name=None):
        constraints = self._constraints_affecting_columns(
                            table_name, [column_name], "FOREIGN KEY")

        primary_key_columns = self._find_primary_key_columns(table_name)

        if len(primary_key_columns) > 1:
            # Composite primary keys cannot be referenced by a foreign key
            return list(constraints)
        else:
            primary_key_columns.add(column_name)
            recursive_constraints = set(self._constraints_affecting_columns(
                                table_name, primary_key_columns, "FOREIGN KEY"))
            return list(recursive_constraints.union(constraints))

    def _digest(self, *args):
        """
        Use django.db.backends.creation.BaseDatabaseCreation._digest
        to create index name in Django style. An evil hack :(
        """
        if not hasattr(self, '_django_db_creation'):
            self._django_db_creation = BaseDatabaseCreation(self._get_connection())
        return self._django_db_creation._digest(*args)

    def shorten_name(self, name):
        return truncate_name(name, self._get_connection().ops.max_name_length())

    def create_index_name(self, table_name, column_names, suffix=""):
        """
        Generate a unique name for the index
        """

        # If there is just one column in the index, use a default algorithm from Django
        if len(column_names) == 1 and not suffix:
            return self.shorten_name(
                '%s_%s' % (table_name, self._digest(column_names[0]))
            )

        # Else generate the name for the index by South
        table_name = table_name.replace('"', '').replace('.', '_')
        index_unique_name = '_%x' % abs(hash((table_name, ','.join(column_names))))

        # If the index name is too long, truncate it
        index_name = ('%s_%s%s%s' % (table_name, column_names[0], index_unique_name, suffix)).replace('"', '').replace('.', '_')
        if len(index_name) > self.max_index_name_length:
            part = ('_%s%s%s' % (column_names[0], index_unique_name, suffix))
            index_name = '%s%s' % (table_name[:(self.max_index_name_length - len(part))], part)

        return index_name
開發者ID:AMHZR,項目名稱:appartments,代碼行數:66,代碼來源:generic.py


注:本文中的django.db.backends.creation.BaseDatabaseCreation類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。