当前位置: 首页>>代码示例>>Python>>正文


Python Server.disable_foreign_key_checks方法代码示例

本文整理汇总了Python中mysql.utilities.common.server.Server.disable_foreign_key_checks方法的典型用法代码示例。如果您正苦于以下问题:Python Server.disable_foreign_key_checks方法的具体用法?Python Server.disable_foreign_key_checks怎么用?Python Server.disable_foreign_key_checks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mysql.utilities.common.server.Server的用法示例。


在下文中一共展示了Server.disable_foreign_key_checks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _bulk_insert

# 需要导入模块: from mysql.utilities.common.server import Server [as 别名]
# 或者: from mysql.utilities.common.server.Server import disable_foreign_key_checks [as 别名]
    def _bulk_insert(self, rows, new_db, destination=None):
        """Import data using bulk insert

        Reads data from a table and builds group INSERT statements for writing
        to the destination server specified (new_db.name).

        This method is designed to be used in a thread for parallel inserts.
        As such, it requires its own connection to the destination server.

        Note: This method does not print any information to stdout.

        rows[in]           a list of rows to process
        new_db[in]         new database name
        destination[in]    the destination server
        """

        from mysql.utilities.common.lock import Lock
        from mysql.utilities.common.server import Server

        if self.dest_vals is None:
            self.dest_vals = self.get_dest_values(destination)

        # Spawn a new connection
        server_options = {
            'conn_info' : self.dest_vals,
            'role'      : "thread",
        }
        dest = Server(server_options)
        dest.connect()

        # Issue the write lock
        lock_list = [("`%s`.`%s`" % (new_db, self.tbl_name), 'WRITE')]
        my_lock = Lock(dest, lock_list, {'locking':'lock-all',})
                    
        # First, turn off foreign keys if turned on
        dest.disable_foreign_key_checks(True)

        if self.column_format is None:
            self.get_column_metadata()

        data_lists = self.make_bulk_insert(rows, new_db)
        insert_data = data_lists[0]
        blob_data = data_lists[1]

        # Insert the data first
        for data_insert in insert_data:
            try:
                res = dest.exec_query(data_insert, self.query_options)
            except UtilError, e:
                raise UtilError("Problem inserting data. "
                                     "Error = %s" % e.errmsg)
开发者ID:dannykopping,项目名称:deploi,代码行数:53,代码来源:table.py


注:本文中的mysql.utilities.common.server.Server.disable_foreign_key_checks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。