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