本文整理匯總了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)