| 1775 | ) |
| 1776 | |
| 1777 | def _process_numeric(self): |
| 1778 | assert self._numeric_binds |
| 1779 | assert self.state is CompilerState.STRING_APPLIED |
| 1780 | |
| 1781 | num = 1 |
| 1782 | param_pos: Dict[str, str] = {} |
| 1783 | order: Iterable[str] |
| 1784 | if self._insertmanyvalues and self._values_bindparam is not None: |
| 1785 | # bindparams that are not in values are always placed first. |
| 1786 | # this avoids the need of changing them when using executemany |
| 1787 | # values () () |
| 1788 | order = itertools.chain( |
| 1789 | ( |
| 1790 | name |
| 1791 | for name in self.bind_names.values() |
| 1792 | if name not in self._values_bindparam |
| 1793 | ), |
| 1794 | self.bind_names.values(), |
| 1795 | ) |
| 1796 | else: |
| 1797 | order = self.bind_names.values() |
| 1798 | |
| 1799 | for bind_name in order: |
| 1800 | if bind_name in param_pos: |
| 1801 | continue |
| 1802 | bind = self.binds[bind_name] |
| 1803 | if ( |
| 1804 | bind in self.post_compile_params |
| 1805 | or bind in self.literal_execute_params |
| 1806 | ): |
| 1807 | # set to None to just mark the in positiontup, it will not |
| 1808 | # be replaced below. |
| 1809 | param_pos[bind_name] = None # type: ignore |
| 1810 | else: |
| 1811 | ph = f"{self._numeric_binds_identifier_char}{num}" |
| 1812 | num += 1 |
| 1813 | param_pos[bind_name] = ph |
| 1814 | |
| 1815 | self.next_numeric_pos = num |
| 1816 | |
| 1817 | self.positiontup = list(param_pos) |
| 1818 | if self.escaped_bind_names: |
| 1819 | len_before = len(param_pos) |
| 1820 | param_pos = { |
| 1821 | self.escaped_bind_names.get(name, name): pos |
| 1822 | for name, pos in param_pos.items() |
| 1823 | } |
| 1824 | assert len(param_pos) == len_before |
| 1825 | |
| 1826 | # Can't use format here since % chars are not escaped. |
| 1827 | self.string = self._pyformat_pattern.sub( |
| 1828 | lambda m: param_pos[m.group(1)], self.string |
| 1829 | ) |
| 1830 | |
| 1831 | if self._insertmanyvalues: |
| 1832 | single_values_expr = ( |
| 1833 | # format is ok here since single_values_expr includes only |
| 1834 | # place-holders |