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

Method invoke_statement

lib/sqlalchemy/orm/session.py:380–484  ·  view source on GitHub ↗

Execute the statement represented by this :class:`.ORMExecuteState`, without re-invoking events that have already proceeded. This method essentially performs a re-entrant execution of the current statement for which the :meth:`.SessionEvents.do_orm_execute` event is

(
        self,
        statement: Optional[Executable] = None,
        params: Optional[_CoreAnyExecuteParams] = None,
        execution_options: Optional[OrmExecuteOptionsParameter] = None,
        bind_arguments: Optional[_BindArguments] = None,
    )

Source from the content-addressed store, hash-verified

378 return self._events_todo[self._starting_event_idx + 1 :]
379
380 def invoke_statement(
381 self,
382 statement: Optional[Executable] = None,
383 params: Optional[_CoreAnyExecuteParams] = None,
384 execution_options: Optional[OrmExecuteOptionsParameter] = None,
385 bind_arguments: Optional[_BindArguments] = None,
386 ) -> Result[Any]:
387 """Execute the statement represented by this
388 :class:`.ORMExecuteState`, without re-invoking events that have
389 already proceeded.
390
391 This method essentially performs a re-entrant execution of the current
392 statement for which the :meth:`.SessionEvents.do_orm_execute` event is
393 being currently invoked. The use case for this is for event handlers
394 that want to override how the ultimate
395 :class:`_engine.Result` object is returned, such as for schemes that
396 retrieve results from an offline cache or which concatenate results
397 from multiple executions.
398
399 When the :class:`_engine.Result` object is returned by the actual
400 handler function within :meth:`_orm.SessionEvents.do_orm_execute` and
401 is propagated to the calling
402 :meth:`_orm.Session.execute` method, the remainder of the
403 :meth:`_orm.Session.execute` method is preempted and the
404 :class:`_engine.Result` object is returned to the caller of
405 :meth:`_orm.Session.execute` immediately.
406
407 :param statement: optional statement to be invoked, in place of the
408 statement currently represented by :attr:`.ORMExecuteState.statement`.
409
410 :param params: optional dictionary of parameters or list of parameters
411 which will be merged into the existing
412 :attr:`.ORMExecuteState.parameters` of this :class:`.ORMExecuteState`.
413
414 .. versionchanged:: 2.0 a list of parameter dictionaries is accepted
415 for executemany executions.
416
417 :param execution_options: optional dictionary of execution options
418 will be merged into the existing
419 :attr:`.ORMExecuteState.execution_options` of this
420 :class:`.ORMExecuteState`.
421
422 :param bind_arguments: optional dictionary of bind_arguments
423 which will be merged amongst the current
424 :attr:`.ORMExecuteState.bind_arguments`
425 of this :class:`.ORMExecuteState`.
426
427 :return: a :class:`_engine.Result` object with ORM-level results.
428
429 .. seealso::
430
431 :ref:`do_orm_execute_re_executing` - background and examples on the
432 appropriate usage of :meth:`_orm.ORMExecuteState.invoke_statement`.
433
434
435 """
436
437 if statement is None:

Callers 6

iter_for_shardFunction · 0.80
oneMethod · 0.80
twoMethod · 0.80
fourMethod · 0.80
execute_and_instancesMethod · 0.80
createfuncMethod · 0.80

Calls 5

castFunction · 0.85
_execute_internalMethod · 0.80
updateMethod · 0.45
appendMethod · 0.45
unionMethod · 0.45

Tested by 4

oneMethod · 0.64
twoMethod · 0.64
fourMethod · 0.64
execute_and_instancesMethod · 0.64