當前位置: 首頁>>代碼示例>>Python>>正文


Python Engine._trans_ctx方法代碼示例

本文整理匯總了Python中sqlalchemy.engine.Engine._trans_ctx方法的典型用法代碼示例。如果您正苦於以下問題:Python Engine._trans_ctx方法的具體用法?Python Engine._trans_ctx怎麽用?Python Engine._trans_ctx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlalchemy.engine.Engine的用法示例。


在下文中一共展示了Engine._trans_ctx方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: begin

# 需要導入模塊: from sqlalchemy.engine import Engine [as 別名]
# 或者: from sqlalchemy.engine.Engine import _trans_ctx [as 別名]
def begin(self, close_with_result=False):
        """Return a context manager delivering a :class:`.Connection`
        with a :class:`.Transaction` established.

        E.g.::

            with engine.begin() as conn:
                conn.execute("insert into table (x, y, z) values (1, 2, 3)")
                conn.execute("my_special_procedure(5)")

        Upon successful operation, the :class:`.Transaction`
        is committed.  If an error is raised, the :class:`.Transaction`
        is rolled back.

        The ``close_with_result`` flag is normally ``False``, and indicates
        that the :class:`.Connection` will be closed when the operation
        is complete.   When set to ``True``, it indicates the
        :class:`.Connection` is in "single use" mode, where the
        :class:`.ResultProxy` returned by the first call to
        :meth:`.Connection.execute` will close the :class:`.Connection` when
        that :class:`.ResultProxy` has exhausted all result rows.

        .. versionadded:: 0.7.6

        See also:

        :meth:`.Engine.connect` - procure a :class:`.Connection` from
        an :class:`.Engine`.

        :meth:`.Connection.begin` - start a :class:`.Transaction`
        for a particular :class:`.Connection`.

        """
        conn = self.contextual_connect(close_with_result=close_with_result)
        try:
            trans = conn.begin()
        except:
            with util.safe_reraise():
                conn.close()
        return Engine._trans_ctx(conn, trans, close_with_result) 
開發者ID:jpush,項目名稱:jbox,代碼行數:42,代碼來源:base.py

示例2: begin

# 需要導入模塊: from sqlalchemy.engine import Engine [as 別名]
# 或者: from sqlalchemy.engine.Engine import _trans_ctx [as 別名]
def begin(self, close_with_result=False):
        """Return a context manager delivering a :class:`_engine.Connection`
        with a :class:`.Transaction` established.

        E.g.::

            with engine.begin() as conn:
                conn.execute(
                    text("insert into table (x, y, z) values (1, 2, 3)")
                )
                conn.execute(text("my_special_procedure(5)"))

        Upon successful operation, the :class:`.Transaction`
        is committed.  If an error is raised, the :class:`.Transaction`
        is rolled back.

        The ``close_with_result`` flag is normally ``False``, and indicates
        that the :class:`_engine.Connection` will be closed when the operation
        is complete.   When set to ``True``, it indicates the
        :class:`_engine.Connection` is in "single use" mode, where the
        :class:`_engine.CursorResult` returned by the first call to
        :meth:`_engine.Connection.execute` will close the
        :class:`_engine.Connection` when
        that :class:`_engine.CursorResult` has exhausted all result rows.

        .. seealso::

            :meth:`_engine.Engine.connect` - procure a
            :class:`_engine.Connection` from
            an :class:`_engine.Engine`.

            :meth:`_engine.Connection.begin` - start a :class:`.Transaction`
            for a particular :class:`_engine.Connection`.

        """
        if self._connection_cls._is_future:
            conn = self.connect()
        else:
            conn = self.connect(close_with_result=close_with_result)
        try:
            trans = conn.begin()
        except:
            with util.safe_reraise():
                conn.close()
        return Engine._trans_ctx(conn, trans, close_with_result) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:47,代碼來源:base.py


注:本文中的sqlalchemy.engine.Engine._trans_ctx方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。