MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / construct_params

Method construct_params

lib/sqlalchemy/sql/compiler.py:1909–2046  ·  view source on GitHub ↗

return a dictionary of bind parameter keys and values

(
        self,
        params: Optional[_CoreSingleExecuteParams] = None,
        extracted_parameters: Optional[Sequence[BindParameter[Any]]] = None,
        escape_names: bool = True,
        _group_number: Optional[int] = None,
        _check: bool = True,
        _no_postcompile: bool = False,
        _collected_params: _CoreSingleExecuteParams | None = None,
    )

Source from the content-addressed store, hash-verified

1907 )
1908
1909 def construct_params(
1910 self,
1911 params: Optional[_CoreSingleExecuteParams] = None,
1912 extracted_parameters: Optional[Sequence[BindParameter[Any]]] = None,
1913 escape_names: bool = True,
1914 _group_number: Optional[int] = None,
1915 _check: bool = True,
1916 _no_postcompile: bool = False,
1917 _collected_params: _CoreSingleExecuteParams | None = None,
1918 ) -> _MutableCoreSingleExecuteParams:
1919 """return a dictionary of bind parameter keys and values"""
1920 if _collected_params is not None:
1921 assert not self._collect_params
1922 elif self._collect_params:
1923 _collected_params = self._collected_params
1924
1925 if _collected_params:
1926 if not params:
1927 params = _collected_params
1928 else:
1929 params = {**_collected_params, **params}
1930
1931 if self._render_postcompile and not _no_postcompile:
1932 assert self._post_compile_expanded_state is not None
1933 if not params:
1934 return dict(self._post_compile_expanded_state.parameters)
1935 else:
1936 raise exc.InvalidRequestError(
1937 "can't construct new parameters when render_postcompile "
1938 "is used; the statement is hard-linked to the original "
1939 "parameters. Use construct_expanded_state to generate a "
1940 "new statement and parameters."
1941 )
1942
1943 has_escaped_names = escape_names and bool(self.escaped_bind_names)
1944
1945 if extracted_parameters:
1946 # related the bound parameters collected in the original cache key
1947 # to those collected in the incoming cache key. They will not have
1948 # matching names but they will line up positionally in the same
1949 # way. The parameters present in self.bind_names may be clones of
1950 # these original cache key params in the case of DML but the .key
1951 # will be guaranteed to match.
1952 if self.cache_key is None:
1953 raise exc.CompileError(
1954 "This compiled object has no original cache key; "
1955 "can't pass extracted_parameters to construct_params"
1956 )
1957 else:
1958 orig_extracted = self.cache_key[1]
1959
1960 ckbm_tuple = self._cache_key_bind_match
1961 assert ckbm_tuple is not None
1962 ckbm, _ = ckbm_tuple
1963 resolved_extracted = {
1964 bind: extracted
1965 for b, extracted in zip(orig_extracted, extracted_parameters)
1966 for bind in ckbm[b]

Callers 3

__init__Method · 0.95
paramsMethod · 0.95

Calls 2

itemsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected