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,
)
| 1858 | ) |
| 1859 | |
| 1860 | def construct_params( |
| 1861 | self, |
| 1862 | params: Optional[_CoreSingleExecuteParams] = None, |
| 1863 | extracted_parameters: Optional[Sequence[BindParameter[Any]]] = None, |
| 1864 | escape_names: bool = True, |
| 1865 | _group_number: Optional[int] = None, |
| 1866 | _check: bool = True, |
| 1867 | _no_postcompile: bool = False, |
| 1868 | ) -> _MutableCoreSingleExecuteParams: |
| 1869 | """return a dictionary of bind parameter keys and values""" |
| 1870 | |
| 1871 | if self._render_postcompile and not _no_postcompile: |
| 1872 | assert self._post_compile_expanded_state is not None |
| 1873 | if not params: |
| 1874 | return dict(self._post_compile_expanded_state.parameters) |
| 1875 | else: |
| 1876 | raise exc.InvalidRequestError( |
| 1877 | "can't construct new parameters when render_postcompile " |
| 1878 | "is used; the statement is hard-linked to the original " |
| 1879 | "parameters. Use construct_expanded_state to generate a " |
| 1880 | "new statement and parameters." |
| 1881 | ) |
| 1882 | |
| 1883 | has_escaped_names = escape_names and bool(self.escaped_bind_names) |
| 1884 | |
| 1885 | if extracted_parameters: |
| 1886 | # related the bound parameters collected in the original cache key |
| 1887 | # to those collected in the incoming cache key. They will not have |
| 1888 | # matching names but they will line up positionally in the same |
| 1889 | # way. The parameters present in self.bind_names may be clones of |
| 1890 | # these original cache key params in the case of DML but the .key |
| 1891 | # will be guaranteed to match. |
| 1892 | if self.cache_key is None: |
| 1893 | raise exc.CompileError( |
| 1894 | "This compiled object has no original cache key; " |
| 1895 | "can't pass extracted_parameters to construct_params" |
| 1896 | ) |
| 1897 | else: |
| 1898 | orig_extracted = self.cache_key[1] |
| 1899 | |
| 1900 | ckbm_tuple = self._cache_key_bind_match |
| 1901 | assert ckbm_tuple is not None |
| 1902 | ckbm, _ = ckbm_tuple |
| 1903 | resolved_extracted = { |
| 1904 | bind: extracted |
| 1905 | for b, extracted in zip(orig_extracted, extracted_parameters) |
| 1906 | for bind in ckbm[b] |
| 1907 | } |
| 1908 | else: |
| 1909 | resolved_extracted = None |
| 1910 | |
| 1911 | if params: |
| 1912 | pd = {} |
| 1913 | for bindparam, name in self.bind_names.items(): |
| 1914 | escaped_name = ( |
| 1915 | self.escaped_bind_names.get(name, name) |
| 1916 | if has_escaped_names |
| 1917 | else name |
no test coverage detected