本文整理汇总了Python中_mysql_connector.MySQL.num_rows方法的典型用法代码示例。如果您正苦于以下问题:Python MySQL.num_rows方法的具体用法?Python MySQL.num_rows怎么用?Python MySQL.num_rows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_mysql_connector.MySQL
的用法示例。
在下文中一共展示了MySQL.num_rows方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rollback
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import num_rows [as 别名]
def test_rollback(self):
cmy1 = MySQL(buffered=True)
cmy1.connect(**self.connect_kwargs)
cmy2 = MySQL(buffered=True)
cmy2.connect(**self.connect_kwargs)
table = "commit_test"
cmy1.query("DROP TABLE IF EXISTS {0}".format(table))
cmy1.query("CREATE TABLE {0} (c1 INT)".format(table))
cmy1.query("START TRANSACTION")
cmy1.query("INSERT INTO {0} (c1) VALUES "
"(1), (2), (3)".format(table))
cmy1.commit()
cmy2.query("SELECT * FROM {0}".format(table))
self.assertEqual([(1,), (2,), (3,)], fetch_rows(cmy2))
cmy1.query("START TRANSACTION")
cmy1.query("INSERT INTO {0} (c1) VALUES "
"(4), (5), (6)".format(table))
cmy1.rollback()
cmy2.query("SELECT * FROM {0}".format(table))
self.assertEqual(3, cmy2.num_rows())
cmy1.query("DROP TABLE IF EXISTS {0}".format(table))
示例2: test_autocommit
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import num_rows [as 别名]
def test_autocommit(self):
cmy1 = MySQL(buffered=True)
cmy1.connect(**self.connect_kwargs)
cmy2 = MySQL(buffered=True)
cmy2.connect(**self.connect_kwargs)
self.assertRaises(ValueError, cmy1.autocommit, 'ham')
self.assertRaises(ValueError, cmy1.autocommit, 1)
self.assertRaises(ValueError, cmy1.autocommit, None)
table = "autocommit_test"
# For the test we start off by making sure the autocommit is off
# for both sessions
cmy1.query("SELECT @@global.autocommit")
if cmy1.fetch_row()[0] != 1:
cmy1.query("SET @@session.autocommit = 0")
cmy2.query("SET @@session.autocommit = 0")
cmy1.query("DROP TABLE IF EXISTS {0}".format(table))
cmy1.query("CREATE TABLE {0} (c1 INT)".format(table))
# Turn AUTOCOMMIT on
cmy1.autocommit(True)
cmy1.query("INSERT INTO {0} (c1) VALUES "
"(1), (2), (3)".format(table))
cmy2.query("SELECT * FROM {0}".format(table))
self.assertEqual(3, cmy2.num_rows())
rows = fetch_rows(cmy2)
# Turn AUTOCOMMIT off
cmy1.autocommit(False)
cmy1.query("INSERT INTO {0} (c1) VALUES "
"(4), (5), (6)".format(table))
cmy2.query("SELECT * FROM {0} WHERE c1 > 3".format(table))
self.assertEqual([], fetch_rows(cmy2))
cmy1.commit()
cmy2.query("SELECT * FROM {0} WHERE c1 > 3".format(table))
self.assertEqual([(4,), (5,), (6,)], fetch_rows(cmy2))
cmy1.query("DROP TABLE IF EXISTS {0}".format(table))
cmy1.close()
cmy2.close()