当前位置: 首页>>代码示例>>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;未经允许,请勿转载。