class documentation

A messenger object for a Dialect that corresponds to a single execution.

Method create_cursor Return a new cursor generated from this ExecutionContext's connection.
Method fire_sequence given a :class:`.Sequence`, invoke it and return the next int value
Method get_out_parameter_values Return a sequence of OUT parameter values from a cursor.
Method get_rowcount Return the DBAPI ``cursor.rowcount`` value, or in some cases an interpreted value.
Method handle_dbapi_exception Receive a DBAPI exception which occurred upon execute, result fetch, etc.
Method lastrow_has_defaults Return True if the last INSERT or UPDATE row contained inlined or database-side defaults.
Method post_exec Called after the execution of a compiled statement.
Method pre_exec Called before an execution of a compiled statement.
Class Variable compiled if passed to constructor, sqlalchemy.engine.base.Compiled object being executed
Class Variable connection Connection object which can be freely used by default value generators to execute SQL. This Connection should reference the same underlying connection/transactional resources of root_connection.
Class Variable cursor DB-API cursor procured from the connection
Class Variable dialect dialect which created this ExecutionContext.
Class Variable engine engine which the Connection is associated with
Class Variable execute_style the style of DBAPI cursor method that will be used to execute a statement.
Class Variable executemany True if the context has a list of more than one parameter set.
Class Variable invoked_statement The Executable statement object that was given in the first place.
Class Variable isinsert True if the statement is an INSERT.
Class Variable isupdate True if the statement is an UPDATE.
Class Variable no_parameters True if the execution style does not use parameters
Class Variable parameters bind parameters passed to the execute() or exec_driver_sql() methods.
Class Variable postfetch_cols a list of Column objects for which a server-side default or inline SQL expression value was fired off. Applies to inserts and updates.
Class Variable prefetch_cols a list of Column objects for which a client-side default was fired off. Applies to inserts and updates.
Class Variable root_connection Connection object which is the source of this ExecutionContext.
Class Variable statement string version of the statement to be executed. Is either passed to the constructor, or must be created from the sql.Compiled object by the time pre_exec() has completed.
Class Method _init_compiled Undocumented
Class Method _init_ddl Undocumented
Class Method _init_default Undocumented
Class Method _init_statement Undocumented
Method _exec_default Undocumented
Method _get_cache_stats Undocumented
Method _prepare_set_input_sizes Undocumented
Method _setup_result_proxy Undocumented
def create_cursor(self) -> DBAPICursor: (source)

Return a new cursor generated from this ExecutionContext's connection. Some dialects may wish to change the behavior of connection.cursor(), such as postgresql which may return a PG "server side" cursor.

def get_out_parameter_values(self, out_param_names: Sequence[str]) -> Sequence[Any]: (source)

Return a sequence of OUT parameter values from a cursor. For dialects that support OUT parameters, this method will be called when there is a :class:`.SQLCompiler` object which has the :attr:`.SQLCompiler.has_out_parameters` flag set. This flag in turn will be set to True if the statement itself has :class:`.BindParameter` objects that have the ``.isoutparam`` flag set which are consumed by the :meth:`.SQLCompiler.visit_bindparam` method. If the dialect compiler produces :class:`.BindParameter` objects with ``.isoutparam`` set which are not handled by :meth:`.SQLCompiler.visit_bindparam`, it should set this flag explicitly. The list of names that were rendered for each bound parameter is passed to the method. The method should then return a sequence of values corresponding to the list of parameter objects. Unlike in previous SQLAlchemy versions, the values can be the **raw values** from the DBAPI; the execution context will apply the appropriate type handler based on what's present in self.compiled.binds and update the values. The processed dictionary will then be made available via the ``.out_parameters`` collection on the result object. Note that SQLAlchemy 1.4 has multiple kinds of result object as part of the 2.0 transition. .. versionadded:: 1.4 - added :meth:`.ExecutionContext.get_out_parameter_values`, which is invoked automatically by the :class:`.DefaultExecutionContext` when there are :class:`.BindParameter` objects with the ``.isoutparam`` flag set. This replaces the practice of setting out parameters within the now-removed ``get_result_proxy()`` method.

def get_rowcount(self) -> Optional[int]: (source)

Return the DBAPI ``cursor.rowcount`` value, or in some cases an interpreted value. See :attr:`_engine.CursorResult.rowcount` for details on this.

def handle_dbapi_exception(self, e: BaseException): (source)

Receive a DBAPI exception which occurred upon execute, result fetch, etc.

def lastrow_has_defaults(self) -> bool: (source)

Return True if the last INSERT or UPDATE row contained inlined or database-side defaults.

def post_exec(self): (source)

Called after the execution of a compiled statement. If a compiled statement was passed to this ExecutionContext, the `last_insert_ids`, `last_inserted_params`, etc. datamembers should be available after this method completes.

def pre_exec(self): (source)

Called before an execution of a compiled statement. If a compiled statement was passed to this ExecutionContext, the `statement` and `parameters` datamembers must be initialized after this statement is complete.

if passed to constructor, sqlalchemy.engine.base.Compiled object being executed

Connection object which can be freely used by default value generators to execute SQL. This Connection should reference the same underlying connection/transactional resources of root_connection.

DB-API cursor procured from the connection

dialect which created this ExecutionContext.

engine which the Connection is associated with

the style of DBAPI cursor method that will be used to execute a statement. .. versionadded:: 2.0

executemany: bool = (source)

True if the context has a list of more than one parameter set. Historically this attribute links to whether ``cursor.execute()`` or ``cursor.executemany()`` will be used. It also can now mean that "insertmanyvalues" may be used which indicates one or more ``cursor.execute()`` calls.

invoked_statement: Optional[Executable] = (source)

The Executable statement object that was given in the first place. This should be structurally equivalent to compiled.statement, but not necessarily the same object as in a caching scenario the compiled form will have been extracted from the cache.

isinsert: bool = (source)

True if the statement is an INSERT.

isupdate: bool = (source)

True if the statement is an UPDATE.

no_parameters: bool = (source)

True if the execution style does not use parameters

bind parameters passed to the execute() or exec_driver_sql() methods. These are always stored as a list of parameter entries. A single-element list corresponds to a ``cursor.execute()`` call and a multiple-element list corresponds to ``cursor.executemany()``, except in the case of :attr:`.ExecuteStyle.INSERTMANYVALUES` which will use ``cursor.execute()`` one or more times.

a list of Column objects for which a server-side default or inline SQL expression value was fired off. Applies to inserts and updates.

a list of Column objects for which a client-side default was fired off. Applies to inserts and updates.

root_connection: Connection = (source)

Connection object which is the source of this ExecutionContext.

statement: str = (source)

string version of the statement to be executed. Is either passed to the constructor, or must be created from the sql.Compiled object by the time pre_exec() has completed.

@classmethod
def _init_compiled(cls, dialect: Dialect, connection: Connection, dbapi_connection: PoolProxiedConnection, execution_options: _ExecuteOptions, compiled: SQLCompiler, parameters: _CoreMultiExecuteParams, invoked_statement: Executable, extracted_parameters: Optional[Sequence[BindParameter[Any]]], cache_hit: CacheStats = CacheStats.CACHING_DISABLED) -> ExecutionContext: (source)
@classmethod
def _init_ddl(cls, dialect: Dialect, connection: Connection, dbapi_connection: PoolProxiedConnection, execution_options: _ExecuteOptions, compiled_ddl: DDLCompiler) -> ExecutionContext: (source)
@classmethod
def _init_default(cls, dialect: Dialect, connection: Connection, dbapi_connection: PoolProxiedConnection, execution_options: _ExecuteOptions) -> ExecutionContext: (source)
@classmethod
def _init_statement(cls, dialect: Dialect, connection: Connection, dbapi_connection: PoolProxiedConnection, execution_options: _ExecuteOptions, statement: str, parameters: _DBAPIMultiExecuteParams) -> ExecutionContext: (source)
def _exec_default(self, column: Optional[Column[Any]], default: DefaultGenerator, type_: Optional[TypeEngine[Any]]) -> Any: (source)
def _get_cache_stats(self) -> str: (source)
def _prepare_set_input_sizes(self) -> Optional[List[Tuple[str, Any, TypeEngine[Any]]]]: (source)
def _setup_result_proxy(self) -> CursorResult[Any]: (source)