MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / statement

Method statement

lib/sqlalchemy/orm/query.py:512–552  ·  view source on GitHub ↗

The full SELECT statement represented by this Query. The statement by default will not have disambiguating labels applied to the construct unless with_labels(True) is called first.

(self)

Source from the content-addressed store, hash-verified

510
511 @property
512 def statement(self) -> Union[Select[_T], FromStatement[_T], UpdateBase]:
513 """The full SELECT statement represented by this Query.
514
515 The statement by default will not have disambiguating labels
516 applied to the construct unless with_labels(True) is called
517 first.
518
519 """
520
521 # .statement can return the direct future.Select() construct here, as
522 # long as we are not using subsequent adaption features that
523 # are made against raw entities, e.g. from_self(), with_polymorphic(),
524 # select_entity_from(). If these features are being used, then
525 # the Select() we return will not have the correct .selected_columns
526 # collection and will not embed in subsequent queries correctly.
527 # We could find a way to make this collection "correct", however
528 # this would not be too different from doing the full compile as
529 # we are doing in any case, the Select() would still not have the
530 # proper state for other attributes like whereclause, order_by,
531 # and these features are all deprecated in any case.
532 #
533 # for these reasons, Query is not a Select, it remains an ORM
534 # object for which __clause_element__() must be called in order for
535 # it to provide a real expression object.
536 #
537 # from there, it starts to look much like Query itself won't be
538 # passed into the execute process and won't generate its own cache
539 # key; this will all occur in terms of the ORM-enabled Select.
540 stmt: Union[Select[_T], FromStatement[_T], UpdateBase]
541
542 if not self._compile_options._set_base_alias:
543 # if we don't have legacy top level aliasing features in use
544 # then convert to a future select() directly
545 stmt = self._statement_20(for_statement=True)
546 else:
547 stmt = self._compile_state(for_statement=True).statement
548
549 if self._params:
550 stmt = stmt.params(self._params)
551
552 return stmt
553
554 def _final_statement(
555 self, legacy_query_style: bool = True

Callers

nothing calls this directly

Calls 3

_statement_20Method · 0.95
_compile_stateMethod · 0.95
paramsMethod · 0.45

Tested by

no test coverage detected