本文整理汇总了Python中_mysql_connector.MySQL.insert_id方法的典型用法代码示例。如果您正苦于以下问题:Python MySQL.insert_id方法的具体用法?Python MySQL.insert_id怎么用?Python MySQL.insert_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_mysql_connector.MySQL
的用法示例。
在下文中一共展示了MySQL.insert_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_insert_id
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import insert_id [as 别名]
def test_insert_id(self):
cmy = MySQL(buffered=True)
cmy.connect(**self.connect_kwargs)
table = "insert_id_test"
cmy.query("DROP TABLE IF EXISTS {0}".format(table))
cmy.query("CREATE TABLE {0} (id INT AUTO_INCREMENT KEY)".format(table))
self.assertEqual(0, cmy.insert_id())
cmy.query("INSERT INTO {0} VALUES ()".format(table))
self.assertEqual(1, cmy.insert_id())
# Multiple-row
cmy.query("INSERT INTO {0} VALUES (), ()".format(table))
self.assertEqual(2, cmy.insert_id())
cmy.query("DROP TABLE IF EXISTS {0}".format(table))
示例2: test_next_result
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import insert_id [as 别名]
def test_next_result(self):
cmy = MySQL()
cmy.connect(**self.connect_kwargs)
table = "next_result_test"
cmy.query("DROP TABLE IF EXISTS {0}".format(table))
cmy.query("CREATE TABLE {0} (c1 INT AUTO_INCREMENT KEY)".format(table))
var_names = ('"HAVE_CRYPT"', '"CHARACTER_SET_CONNECTION"')
queries = (
"SELECT VARIABLE_NAME FROM INFORMATION_SCHEMA.SESSION_VARIABLES "
"WHERE VARIABLE_NAME IN ({0})".format(','.join(var_names)),
"SELECT 'HAM'",
"INSERT INTO {0} () VALUES ()".format(table),
"SELECT 'SPAM'",
)
exp = [
[(b'HAVE_CRYPT',), (b'CHARACTER_SET_CONNECTION',)],
[(b'HAM',)],
{'insert_id': 1, 'affected': 1},
[(b'SPAM',)]
]
result = []
have_more = cmy.query(';'.join(queries))
self.assertTrue(have_more)
while have_more:
if cmy.have_result_set:
rows = []
row = cmy.fetch_row()
while row:
rows.append(row)
row = cmy.fetch_row()
result.append(rows)
else:
result.append({
"affected": cmy.affected_rows(),
"insert_id": cmy.insert_id()
})
have_more = cmy.next_result()
self.assertEqual(exp, result)