本文整理汇总了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)