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


Python TRN.add方法代码示例

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


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

示例1: test_context_manager_multiple_2

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

        def tester():
            self.assertEqual(TRN._contexts_entered, 1)
            with TRN:
                self.assertEqual(TRN._contexts_entered, 2)
                sql = """SELECT EXISTS(
                         SELECT * FROM barcodes.test_table
                         WHERE int_column=%s)"""
                TRN.add(sql, [2])
                self.assertTrue(TRN.execute_fetchlast())
            self.assertEqual(TRN._contexts_entered, 1)

        with TRN:
            self.assertEqual(TRN._contexts_entered, 1)
            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)
            tester()
            self.assertEqual(TRN._contexts_entered, 1)
            self._assert_sql_equal([])

        self.assertEqual(TRN._contexts_entered, 0)
        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,代码行数:32,代码来源:test_sql_connection.py

示例2: test_context_manager_multiple

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

        with TRN:
            self.assertEqual(TRN._contexts_entered, 1)

            TRN.add("SELECT 42")
            with TRN:
                self.assertEqual(TRN._contexts_entered, 2)
                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)

            # We exited the second context, nothing should have been executed
            self.assertEqual(TRN._contexts_entered, 1)
            self.assertEqual(
                TRN._connection.get_transaction_status(),
                TRANSACTION_STATUS_IDLE)
            self._assert_sql_equal([])

        # We have exited the first context, everything should have been
        # executed and committed
        self.assertEqual(TRN._contexts_entered, 0)
        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,代码行数:31,代码来源:test_sql_connection.py

示例3: test_post_commit_funcs_error

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import add [as 别名]
    def test_post_commit_funcs_error(self):
        def func():
            raise ValueError()

        with self.assertRaises(RuntimeError):
            with TRN:
                TRN.add("SELECT 42")
                TRN.add_post_commit_func(func)
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:10,代码来源:test_sql_connection.py

示例4: test_add_many

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

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

            exp = [(sql, [1]), (sql, [2]), (sql, [3])]
            self.assertEqual(TRN._queries, exp)
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:12,代码来源:test_sql_connection.py

示例5: tester

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import add [as 别名]
 def tester():
     self.assertEqual(TRN._contexts_entered, 1)
     with TRN:
         self.assertEqual(TRN._contexts_entered, 2)
         sql = """SELECT EXISTS(
                  SELECT * FROM barcodes.test_table
                  WHERE int_column=%s)"""
         TRN.add(sql, [2])
         self.assertTrue(TRN.execute_fetchlast())
     self.assertEqual(TRN._contexts_entered, 1)
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:12,代码来源:test_sql_connection.py

示例6: test_execute_return

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import add [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

示例7: test_execute_fetchlast

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import add [as 别名]
    def test_execute_fetchlast(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 = """SELECT EXISTS(
                     SELECT * FROM barcodes.test_table WHERE int_column=%s)"""
            TRN.add(sql, [2])
            self.assertTrue(TRN.execute_fetchlast())
开发者ID:tanaes,项目名称:plate-mapper,代码行数:13,代码来源:test_sql_connection.py

示例8: make_environment

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import add [as 别名]
def make_environment(test=True):
    """Sets up the database with the schema and optionally test information

    Parameters
    ----------
    test : bool, optional
        Whether the environment will be set up as test or not. Default True
    """
    with TRN:
        with open(join(dirname(abspath(__file__)), '..', 'db',
                       'platemapper.sql')) as f:
            TRN.add(f.read())
开发者ID:tanaes,项目名称:plate-mapper,代码行数:14,代码来源:environment.py

示例9: test_execute_fetchindex

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import add [as 别名]
    def test_execute_fetchindex(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)
            self.assertEqual(TRN.execute_fetchindex(), [['insert3', 3]])

            sql = """INSERT INTO barcodes.test_table (str_column, int_column)
                     VALUES (%s, %s) RETURNING str_column, int_column"""
            args = [['insert4', 4], ['insert5', 5], ['insert6', 6]]
            TRN.add(sql, args, many=True)
            self.assertEqual(TRN.execute_fetchindex(3), [['insert4', 4]])
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:15,代码来源:test_sql_connection.py

示例10: test_context_manager_execute

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import add [as 别名]
    def test_context_manager_execute(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)
            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,代码行数:15,代码来源:test_sql_connection.py

示例11: test_post_commit_funcs

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import add [as 别名]
    def test_post_commit_funcs(self):
        fd, fp = mkstemp()
        close(fd)
        self._files_to_remove.append(fp)

        def func(fp):
            with open(fp, 'w') as f:
                f.write('\n')

        with TRN:
            TRN.add("SELECT 42")
            TRN.add_post_commit_func(func, fp)

        self.assertTrue(exists(fp))
开发者ID:squirrelo,项目名称:plate-mapper,代码行数:16,代码来源:test_sql_connection.py

示例12: test_execute

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import add [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

示例13: test_execute_commit_false_rollback

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import add [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

示例14: test_context_manager_rollback

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import add [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

示例15: test_rollback_transaction

# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import add [as 别名]
    def test_rollback_transaction(self):
        # Create decorated test function that adds a table
        @rollback_transaction
        def testfunc():
            with TRN:
                sql = 'CREATE TABLE barcodes.rollback(test varchar NOT NULL)'
                TRN.add(sql)
                TRN.execute()

        # Make sure that table does not exist once function completes
        testfunc()
        with TRN:
            sql = """SELECT *
                     FROM information_schema.tables
                     WHERE table_schema = 'barcodes'"""
            TRN.add(sql)
            obs = TRN.execute_fetchflatten()
            self.assertNotIn('rollback', obs)
开发者ID:tanaes,项目名称:plate-mapper,代码行数:20,代码来源:test_util.py


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