本文整理汇总了Python中_mysql_connector.MySQL.close方法的典型用法代码示例。如果您正苦于以下问题:Python MySQL.close方法的具体用法?Python MySQL.close怎么用?Python MySQL.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_mysql_connector.MySQL
的用法示例。
在下文中一共展示了MySQL.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_connected
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import close [as 别名]
def test_connected(self):
config = self.connect_kwargs.copy()
cmy = MySQL()
self.assertFalse(cmy.connected())
cmy.connect(**config)
self.assertTrue(cmy.connected())
cmy.close()
self.assertFalse(cmy.connected())
示例2: test_thread_id
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import close [as 别名]
def test_thread_id(self):
cmy = MySQL()
self.assertRaises(MySQLInterfaceError, cmy.thread_id)
cmy.connect(**self.connect_kwargs)
if tests.PY2:
self.assertIsInstance(cmy.thread_id(), long)
else:
self.assertIsInstance(cmy.thread_id(), int)
self.assertGreater(cmy.thread_id(), 0)
thread_id = cmy.thread_id()
cmy.close()
self.assertRaises(MySQLError, cmy.thread_id)
示例3: test_autocommit
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import close [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()
示例4: test_connect
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import close [as 别名]
def test_connect(self):
config = self.connect_kwargs.copy()
cmy = MySQL()
self.assertFalse(cmy.ping())
# Using Unix Socket
cmy.connect(**config)
self.assertTrue(cmy.ping())
# Using TCP
config['unix_socket'] = None
cmy.connect(**config)
self.assertTrue(cmy.ping())
self.assertEqual(None, cmy.close())
self.assertFalse(cmy.ping())
self.assertEqual(None, cmy.close())