MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / begin_twophase

Method begin_twophase

lib/sqlalchemy/engine/base.py:961–989  ·  view source on GitHub ↗

Begin a two-phase or XA transaction and return a transaction handle. The returned object is an instance of :class:`.TwoPhaseTransaction`, which in addition to the methods provided by :class:`.Transaction`, also provides a :meth:`~.TwoPhaseTransaction.prepare`

(self, xid: Optional[Any] = None)

Source from the content-addressed store, hash-verified

959 return NestedTransaction(self)
960
961 def begin_twophase(self, xid: Optional[Any] = None) -> TwoPhaseTransaction:
962 """Begin a two-phase or XA transaction and return a transaction
963 handle.
964
965 The returned object is an instance of :class:`.TwoPhaseTransaction`,
966 which in addition to the methods provided by
967 :class:`.Transaction`, also provides a
968 :meth:`~.TwoPhaseTransaction.prepare` method.
969
970 :param xid: the two phase transaction id. If not supplied, a
971 random id will be generated. The accepted type and value depends on
972 the driver in use.
973
974 .. seealso::
975
976 :meth:`_engine.Connection.begin`
977
978 :meth:`_engine.Connection.begin_twophase`
979
980 """
981
982 if self._transaction is not None:
983 raise exc.InvalidRequestError(
984 "Cannot start a two phase transaction when a transaction "
985 "is already in progress."
986 )
987 if xid is None:
988 xid = self.engine.dialect.create_xid()
989 return TwoPhaseTransaction(self, xid)
990
991 def commit(self) -> None:
992 """Commit the transaction that is currently in progress.

Calls 2

TwoPhaseTransactionClass · 0.85
create_xidMethod · 0.45