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

Function _get_crud_params

lib/sqlalchemy/sql/crud.py:115–432  ·  view source on GitHub ↗

create a set of tuples representing column/string pairs for use in an INSERT or UPDATE statement. Also generates the Compiled object's postfetch, prefetch, and returning column collections, used for default handling and ultimately populating the CursorResult's prefetch_cols() and po

(
    compiler: SQLCompiler,
    stmt: ValuesBase,
    compile_state: DMLState,
    toplevel: bool,
    **kw: Any,
)

Source from the content-addressed store, hash-verified

113
114
115def _get_crud_params(
116 compiler: SQLCompiler,
117 stmt: ValuesBase,
118 compile_state: DMLState,
119 toplevel: bool,
120 **kw: Any,
121) -> _CrudParams:
122 """create a set of tuples representing column/string pairs for use
123 in an INSERT or UPDATE statement.
124
125 Also generates the Compiled object's postfetch, prefetch, and
126 returning column collections, used for default handling and ultimately
127 populating the CursorResult's prefetch_cols() and postfetch_cols()
128 collections.
129
130 """
131
132 # note: the _get_crud_params() system was written with the notion in mind
133 # that INSERT, UPDATE, DELETE are always the top level statement and
134 # that there is only one of them. With the addition of CTEs that can
135 # make use of DML, this assumption is no longer accurate; the DML
136 # statement is not necessarily the top-level "row returning" thing
137 # and it is also theoretically possible (fortunately nobody has asked yet)
138 # to have a single statement with multiple DMLs inside of it via CTEs.
139
140 # the current _get_crud_params() design doesn't accommodate these cases
141 # right now. It "just works" for a CTE that has a single DML inside of
142 # it, and for a CTE with multiple DML, it's not clear what would happen.
143
144 # overall, the "compiler.XYZ" collections here would need to be in a
145 # per-DML structure of some kind, and DefaultDialect would need to
146 # navigate these collections on a per-statement basis, with additional
147 # emphasis on the "toplevel returning data" statement. However we
148 # still need to run through _get_crud_params() for all DML as we have
149 # Python / SQL generated column defaults that need to be rendered.
150
151 # if there is user need for this kind of thing, it's likely a post 2.0
152 # kind of change as it would require deep changes to DefaultDialect
153 # as well as here.
154
155 compiler.postfetch = []
156 compiler.insert_prefetch = []
157 compiler.update_prefetch = []
158 compiler.implicit_returning = []
159
160 visiting_cte = kw.get("visiting_cte", None)
161 if visiting_cte is not None:
162 # for insert -> CTE -> insert, don't populate an incoming
163 # _crud_accumulate_bind_names collection; the INSERT we process here
164 # will not be inline within the VALUES of the enclosing INSERT as the
165 # CTE is placed on the outside. See issue #9173
166 kw.pop("accumulate_bind_names", None)
167 assert (
168 "accumulate_bind_names" not in kw
169 ), "Don't know how to handle insert within insert without a CTE"
170
171 # getters - these are normally just column.key,
172 # but in the case of mysql multi-table update, the rules for

Callers

nothing calls this directly

Calls 15

_CrudParamsClass · 0.85
_create_bind_paramFunction · 0.85
_column_as_keyFunction · 0.85
_scan_colsFunction · 0.85
castFunction · 0.85
_as_dml_columnFunction · 0.85

Tested by

no test coverage detected