Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Calcul scientifique
avec Python
Voir le programme détaillé
Classe « Connection »

Méthode sqlalchemy.Connection.begin

Signature de la méthode begin

def begin(self) -> 'RootTransaction' 

Description

help(Connection.begin)

Begin a transaction prior to autobegin occurring.

E.g.::

    with engine.connect() as conn:
        with conn.begin() as trans:
            conn.execute(table.insert(), {"username": "sandy"})

The returned object is an instance of :class:`_engine.RootTransaction`.
This object represents the "scope" of the transaction,
which completes when either the :meth:`_engine.Transaction.rollback`
or :meth:`_engine.Transaction.commit` method is called; the object
also works as a context manager as illustrated above.

The :meth:`_engine.Connection.begin` method begins a
transaction that normally will be begun in any case when the connection
is first used to execute a statement.  The reason this method might be
used would be to invoke the :meth:`_events.ConnectionEvents.begin`
event at a specific time, or to organize code within the scope of a
connection checkout in terms of context managed blocks, such as::

    with engine.connect() as conn:
        with conn.begin():
            conn.execute(...)
            conn.execute(...)

        with conn.begin():
            conn.execute(...)
            conn.execute(...)

The above code is not  fundamentally any different in its behavior than
the following code  which does not use
:meth:`_engine.Connection.begin`; the below style is known
as "commit as you go" style::

    with engine.connect() as conn:
        conn.execute(...)
        conn.execute(...)
        conn.commit()

        conn.execute(...)
        conn.execute(...)
        conn.commit()

From a database point of view, the :meth:`_engine.Connection.begin`
method does not emit any SQL or change the state of the underlying
DBAPI connection in any way; the Python DBAPI does not have any
concept of explicit transaction begin.

.. seealso::

    :ref:`tutorial_working_with_transactions` - in the
    :ref:`unified_tutorial`

    :meth:`_engine.Connection.begin_nested` - use a SAVEPOINT

    :meth:`_engine.Connection.begin_twophase` -
    use a two phase /XID transaction

    :meth:`_engine.Engine.begin` - context manager available from
    :class:`_engine.Engine`



Vous êtes un professionnel et vous avez besoin d'une formation ? RAG (Retrieval-Augmented Generation)
et Fine Tuning d'un LLM
Voir le programme détaillé