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


Python sql_connection.TRN类代码示例

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


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

示例1: test_context_manager_multiple_2

    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,代码行数:30,代码来源:test_sql_connection.py

示例2: test_context_manager_multiple

    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,代码行数:29,代码来源:test_sql_connection.py

示例3: test_post_commit_funcs_error

    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,代码行数:8,代码来源:test_sql_connection.py

示例4: tester

 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,代码行数:10,代码来源:test_sql_connection.py

示例5: test_execute_return

 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,代码行数:10,代码来源:test_sql_connection.py

示例6: test_add_many

    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,代码行数:10,代码来源:test_sql_connection.py

示例7: test_execute_fetchlast

    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,代码行数:11,代码来源:test_sql_connection.py

示例8: make_environment

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,代码行数:12,代码来源:environment.py

示例9: test_context_manager_execute

    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,代码行数:13,代码来源:test_sql_connection.py

示例10: test_post_commit_funcs

    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,代码行数:14,代码来源:test_sql_connection.py

示例11: test_execute

    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,代码行数:14,代码来源:test_sql_connection.py

示例12: test_context_manager_rollback

    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,代码行数:16,代码来源:test_sql_connection.py

示例13: test_execute_commit_false_rollback

    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,代码行数:16,代码来源:test_sql_connection.py

示例14: test_rollback_transaction

    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,代码行数:18,代码来源:test_util.py

示例15: test_execute_many

    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,代码行数:18,代码来源:test_sql_connection.py


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