本文整理匯總了Python中mysql.utilities.common.server.Server.commit方法的典型用法代碼示例。如果您正苦於以下問題:Python Server.commit方法的具體用法?Python Server.commit怎麽用?Python Server.commit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mysql.utilities.common.server.Server
的用法示例。
在下文中一共展示了Server.commit方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_test_data
# 需要導入模塊: from mysql.utilities.common.server import Server [as 別名]
# 或者: from mysql.utilities.common.server.Server import commit [as 別名]
def load_test_data(server, db_num=1):
"""Load/insert data into the test databases.
A considerable amount of data should be considered in order to take some
time to load, allowing mysqlrplsync to be executed at the same time the
data is still being inserted.
server[in] Target server to load the test data.
db_num[in] Number of databases to load the data (by default: 1).
It is assumed that a matching number of test databases
have been previously created.
Note: method prepared to be invoked by a different thread.
"""
# Create a new server instance with a new connection (for multithreading).
srv = Server({'conn_info': server})
srv.connect()
for db_index in xrange(db_num):
db_name = '`test_rplsync_db{0}`'.format(
'' if db_num == 1 else db_index
)
# Insert random data on all tables.
random_values = string.letters + string.digits
for _ in xrange(TEST_DB_NUM_ROWS):
columns = []
values = []
for table_index in xrange(TEST_DB_NUM_TABLES):
columns.append('rnd_txt{0}'.format(table_index))
rnd_text = "".join(
[random.choice(random_values) for _ in xrange(20)]
)
values.append("'{0}'".format(rnd_text))
insert = ("INSERT INTO {0}.`t{1}` ({2}) VALUES ({3})"
"").format(db_name, table_index, ', '.join(columns),
', '.join(values))
srv.exec_query(insert)
srv.commit()