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


Python MySQL.commit方法代码示例

本文整理汇总了Python中_mysql_connector.MySQL.commit方法的典型用法代码示例。如果您正苦于以下问题:Python MySQL.commit方法的具体用法?Python MySQL.commit怎么用?Python MySQL.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在_mysql_connector.MySQL的用法示例。


在下文中一共展示了MySQL.commit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_rollback

# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import commit [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))
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:30,代码来源:test_cext_api.py

示例2: test_autocommit

# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import commit [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

示例3: test_field_count

# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import commit [as 别名]
    def test_field_count(self):
        cmy = MySQL(buffered=True)
        cmy.connect(**self.connect_kwargs)

        table = "field_count"

        cmy.select_db('myconnpy')
        cmy.query("DROP TABLE IF EXISTS {0}".format(table))
        cmy.query("CREATE TABLE {0} (c1 INT, c2 INT, c3 INT)".format(table))

        cmy.query("SELECT * FROM {0}".format(table))
        self.assertEqual(3, cmy.field_count())
        cmy.free_result()

        cmy.query("INSERT INTO {0} (c1, c2, c3) VALUES "
                  "(1, 10, 100)".format(table))
        cmy.commit()

        cmy.query("SELECT * FROM {0}".format(table))
        self.assertEqual(3, cmy.field_count())
        cmy.free_result()

        cmy.query("DROP TABLE IF EXISTS {0}".format(table))
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:25,代码来源:test_cext_api.py


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