当前位置: 首页>>代码示例>>Python>>正文


Python MySQL.close方法代码示例

本文整理汇总了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())
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:10,代码来源:test_cext_api.py

示例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)
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:17,代码来源:test_cext_api.py

示例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()
开发者ID:dveeden,项目名称:mysql-connector-python,代码行数:48,代码来源:test_cext_api.py

示例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())
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:20,代码来源:test_cext_api.py


注:本文中的_mysql_connector.MySQL.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。