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

Method _statement_20

lib/sqlalchemy/orm/query.py:557–607  ·  view source on GitHub ↗
(
        self, for_statement: bool = False, use_legacy_query_style: bool = True
    )

Source from the content-addressed store, hash-verified

555 ).statement # type: ignore
556
557 def _statement_20(
558 self, for_statement: bool = False, use_legacy_query_style: bool = True
559 ) -> Union[Select[_T], FromStatement[_T]]:
560 # TODO: this event needs to be deprecated, as it currently applies
561 # only to ORM query and occurs at this spot that is now more
562 # or less an artificial spot
563 if self.dispatch.before_compile:
564 for fn in self.dispatch.before_compile:
565 new_query = fn(self)
566 if new_query is not None and new_query is not self:
567 self = new_query
568 if not fn._bake_ok: # type: ignore
569 self._compile_options += {"_bake_ok": False}
570
571 compile_options = self._compile_options
572 compile_options += {
573 "_for_statement": for_statement,
574 "_use_legacy_query_style": use_legacy_query_style,
575 }
576
577 stmt: Union[Select[_T], FromStatement[_T]]
578
579 if self._statement is not None:
580 stmt = FromStatement(self._raw_columns, self._statement)
581 stmt.__dict__.update(
582 _with_options=self._with_options,
583 _with_context_options=self._with_context_options,
584 _compile_options=compile_options,
585 _execution_options=self._execution_options,
586 _propagate_attrs=self._propagate_attrs,
587 )
588 else:
589 # Query / select() internal attributes are 99% cross-compatible
590 stmt = Select._create_raw_select(**self.__dict__)
591 stmt.__dict__.update(
592 _label_style=self._label_style,
593 _compile_options=compile_options,
594 _propagate_attrs=self._propagate_attrs,
595 )
596 stmt.__dict__.pop("session", None)
597
598 # ensure the ORM context is used to compile the statement, even
599 # if it has no ORM entities. This is so ORM-only things like
600 # _legacy_joins are picked up that wouldn't be picked up by the
601 # Core statement context
602 if "compile_state_plugin" not in stmt._propagate_attrs:
603 stmt._propagate_attrs = stmt._propagate_attrs.union(
604 {"compile_state_plugin": "orm", "plugin_subject": None}
605 )
606
607 return stmt
608
609 def subquery(
610 self,

Callers 9

statementMethod · 0.95
_iterMethod · 0.95
__str__Method · 0.95
_compile_stateMethod · 0.95
_bakeMethod · 0.80
assert_compileMethod · 0.80
stmt_20Function · 0.80
_stmt_20Method · 0.80

Calls 5

FromStatementClass · 0.85
_create_raw_selectMethod · 0.80
updateMethod · 0.45
popMethod · 0.45
unionMethod · 0.45

Tested by 3

stmt_20Function · 0.64
_stmt_20Method · 0.64