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


Python TRN.execute方法代码示例

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


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

示例1: test_context_manager_no_commit

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import execute [as 别名]
    def test_context_manager_no_commit(self):
        with TRN:
            sql = """INSERT INTO barcodes.test_table (str_column, int_column)
                 VALUES (%s, %s) RETURNING str_column, int_column"""
            args = [['insert1', 1], ['insert2', 2], ['insert3', 3]]
            TRN.add(sql, args, many=True)

            TRN.execute()
            self._assert_sql_equal([])

        self._assert_sql_equal([('insert1', True, 1), ('insert2', True, 2),
                                ('insert3', True, 3)])
        self.assertEqual(
            TRN._connection.get_transaction_status(),
            TRANSACTION_STATUS_IDLE)
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:17,代码来源:test_sql_connection.py

示例2: test_context_manager_rollback

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import execute [as 别名]
    def test_context_manager_rollback(self):
        try:
            with TRN:
                sql = """INSERT INTO barcodes.test_table (str_column, int_column)
                     VALUES (%s, %s) RETURNING str_column, int_column"""
                args = [['insert1', 1], ['insert2', 2], ['insert3', 3]]
                TRN.add(sql, args, many=True)

                TRN.execute()
                raise ValueError("Force exiting the context manager")
        except ValueError:
            pass
        self._assert_sql_equal([])
        self.assertEqual(
            TRN._connection.get_transaction_status(),
            TRANSACTION_STATUS_IDLE)
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:18,代码来源:test_sql_connection.py

示例3: test_context_manager_checker

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import execute [as 别名]
    def test_context_manager_checker(self):
        with self.assertRaises(RuntimeError):
            TRN.add("SELECT 42")

        with self.assertRaises(RuntimeError):
            TRN.execute()

        with self.assertRaises(RuntimeError):
            TRN.commit()

        with self.assertRaises(RuntimeError):
            TRN.rollback()

        with TRN:
            TRN.add("SELECT 42")

        with self.assertRaises(RuntimeError):
            TRN.execute()
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:20,代码来源:test_sql_connection.py

示例4: test_index

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import execute [as 别名]
    def test_index(self):
        with TRN:
            self.assertEqual(TRN.index, 0)

            TRN.add("SELECT 42")
            self.assertEqual(TRN.index, 1)

            sql = "INSERT INTO barcodes.test_table (int_column) VALUES (%s)"
            args = [[1], [2], [3]]
            TRN.add(sql, args, many=True)
            self.assertEqual(TRN.index, 4)

            TRN.execute()
            self.assertEqual(TRN.index, 4)

            TRN.add(sql, args, many=True)
            self.assertEqual(TRN.index, 7)

        self.assertEqual(TRN.index, 0)
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:21,代码来源:test_sql_connection.py

示例5: test_execute_return

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import execute [as 别名]
 def test_execute_return(self):
     with TRN:
         sql = """INSERT INTO barcodes.test_table (str_column, int_column)
                  VALUES (%s, %s) RETURNING str_column, int_column"""
         TRN.add(sql, ['test_insert', 2])
         sql = """UPDATE barcodes.test_table SET bool_column = %s
                  WHERE str_column = %s RETURNING int_column"""
         TRN.add(sql, [False, 'test_insert'])
         obs = TRN.execute()
         self.assertEqual(obs, [[['test_insert', 2]], [[2]]])
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:12,代码来源:test_sql_connection.py

示例6: test_execute_huge_transaction

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import execute [as 别名]
    def test_execute_huge_transaction(self):
        with TRN:
            # Add a lot of inserts to the transaction
            sql = "INSERT INTO barcodes.test_table (int_column) VALUES (%s)"
            for i in range(1000):
                TRN.add(sql, [i])
            # Add some updates to the transaction
            sql = """UPDATE barcodes.test_table SET bool_column = %s
                     WHERE int_column = %s"""
            for i in range(500):
                TRN.add(sql, [False, i])
            # Make the transaction fail with the last insert
            sql = """INSERT INTO barcodes.table_to_make (the_trans_to_fail)
                     VALUES (1)"""
            TRN.add(sql)

            with self.assertRaises(ValueError):
                TRN.execute()

            # make sure rollback correctly
            self._assert_sql_equal([])
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:23,代码来源:test_sql_connection.py

示例7: test_execute

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import execute [as 别名]
    def test_execute(self):
        with TRN:
            sql = """INSERT INTO barcodes.test_table (str_column, int_column)
                     VALUES (%s, %s)"""
            TRN.add(sql, ["test_insert", 2])
            sql = """UPDATE barcodes.test_table
                     SET int_column = %s, bool_column = %s
                     WHERE str_column = %s"""
            TRN.add(sql, [20, False, "test_insert"])
            obs = TRN.execute()
            self.assertEqual(obs, [None, None])
            self._assert_sql_equal([])

        self._assert_sql_equal([("test_insert", False, 20)])
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:16,代码来源:test_sql_connection.py

示例8: test_execute_commit_false_wipe_queries

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import execute [as 别名]
    def test_execute_commit_false_wipe_queries(self):
        with TRN:
            sql = """INSERT INTO barcodes.test_table (str_column, int_column)
                     VALUES (%s, %s) RETURNING str_column, int_column"""
            args = [['insert1', 1], ['insert2', 2], ['insert3', 3]]
            TRN.add(sql, args, many=True)

            obs = TRN.execute()
            exp = [[['insert1', 1]], [['insert2', 2]], [['insert3', 3]]]
            self.assertEqual(obs, exp)

            self._assert_sql_equal([])

            sql = """UPDATE barcodes.test_table SET bool_column = %s
                     WHERE str_column = %s"""
            args = [False, 'insert2']
            TRN.add(sql, args)
            self.assertEqual(TRN._queries, [(sql, args)])

            TRN.execute()
            self._assert_sql_equal([])

        self._assert_sql_equal([('insert1', True, 1), ('insert3', True, 3),
                                ('insert2', False, 2)])
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:26,代码来源:test_sql_connection.py

示例9: test_execute_commit_false_rollback

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import execute [as 别名]
    def test_execute_commit_false_rollback(self):
        with TRN:
            sql = """INSERT INTO barcodes.test_table (str_column, int_column)
                     VALUES (%s, %s) RETURNING str_column, int_column"""
            args = [['insert1', 1], ['insert2', 2], ['insert3', 3]]
            TRN.add(sql, args, many=True)

            obs = TRN.execute()
            exp = [[['insert1', 1]], [['insert2', 2]], [['insert3', 3]]]
            self.assertEqual(obs, exp)

            self._assert_sql_equal([])

            TRN.rollback()

            self._assert_sql_equal([])
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:18,代码来源:test_sql_connection.py

示例10: test_execute_many

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import execute [as 别名]
    def test_execute_many(self):
        with TRN:
            sql = """INSERT INTO barcodes.test_table (str_column, int_column)
                     VALUES (%s, %s)"""
            args = [['insert1', 1], ['insert2', 2], ['insert3', 3]]
            TRN.add(sql, args, many=True)
            sql = """UPDATE barcodes.test_table
                     SET int_column = %s, bool_column = %s
                     WHERE str_column = %s"""
            TRN.add(sql, [20, False, 'insert2'])
            obs = TRN.execute()
            self.assertEqual(obs, [None, None, None, None])

            self._assert_sql_equal([])

        self._assert_sql_equal([('insert1', True, 1),
                                ('insert3', True, 3),
                                ('insert2', False, 20)])
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:20,代码来源:test_sql_connection.py

示例11: test_execute_return_many

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import execute [as 别名]
 def test_execute_return_many(self):
     with TRN:
         sql = """INSERT INTO barcodes.test_table (str_column, int_column)
                  VALUES (%s, %s) RETURNING str_column, int_column"""
         args = [['insert1', 1], ['insert2', 2], ['insert3', 3]]
         TRN.add(sql, args, many=True)
         sql = """UPDATE barcodes.test_table SET bool_column = %s
                  WHERE str_column = %s"""
         TRN.add(sql, [False, 'insert2'])
         sql = "SELECT * FROM barcodes.test_table"
         TRN.add(sql)
         obs = TRN.execute()
         exp = [[['insert1', 1]],  # First query of the many query
                [['insert2', 2]],  # Second query of the many query
                [['insert3', 3]],  # Third query of the many query
                None,  # Update query
                [['insert1', True, 1],  # First result select
                 ['insert3', True, 3],  # Second result select
                 ['insert2', False, 2]]]  # Third result select
         self.assertEqual(obs, exp)
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:22,代码来源:test_sql_connection.py

示例12: testfunc

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import execute [as 别名]
 def testfunc():
     with TRN:
         sql = 'CREATE TABLE barcodes.rollback(test varchar NOT NULL)'
         TRN.add(sql)
         TRN.execute()
开发者ID:tanaes,项目名称:plate-mapper,代码行数:7,代码来源:test_util.py


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