(
self,
name: str,
post_compile: bool = False,
expanding: bool = False,
escaped_from: Optional[str] = None,
bindparam_type: Optional[TypeEngine[Any]] = None,
accumulate_bind_names: Optional[Set[str]] = None,
visited_bindparam: Optional[List[str]] = None,
**kw: Any,
)
| 4157 | return name % self.anon_map |
| 4158 | |
| 4159 | def bindparam_string( |
| 4160 | self, |
| 4161 | name: str, |
| 4162 | post_compile: bool = False, |
| 4163 | expanding: bool = False, |
| 4164 | escaped_from: Optional[str] = None, |
| 4165 | bindparam_type: Optional[TypeEngine[Any]] = None, |
| 4166 | accumulate_bind_names: Optional[Set[str]] = None, |
| 4167 | visited_bindparam: Optional[List[str]] = None, |
| 4168 | **kw: Any, |
| 4169 | ) -> str: |
| 4170 | # TODO: accumulate_bind_names is passed by crud.py to gather |
| 4171 | # names on a per-value basis, visited_bindparam is passed by |
| 4172 | # visit_insert() to collect all parameters in the statement. |
| 4173 | # see if this gathering can be simplified somehow |
| 4174 | if accumulate_bind_names is not None: |
| 4175 | accumulate_bind_names.add(name) |
| 4176 | if visited_bindparam is not None: |
| 4177 | visited_bindparam.append(name) |
| 4178 | |
| 4179 | if not escaped_from: |
| 4180 | if self._bind_translate_re.search(name): |
| 4181 | # not quite the translate use case as we want to |
| 4182 | # also get a quick boolean if we even found |
| 4183 | # unusual characters in the name |
| 4184 | new_name = self._bind_translate_re.sub( |
| 4185 | lambda m: self._bind_translate_chars[m.group(0)], |
| 4186 | name, |
| 4187 | ) |
| 4188 | escaped_from = name |
| 4189 | name = new_name |
| 4190 | |
| 4191 | if escaped_from: |
| 4192 | self.escaped_bind_names = self.escaped_bind_names.union( |
| 4193 | {escaped_from: name} |
| 4194 | ) |
| 4195 | if post_compile: |
| 4196 | ret = "__[POSTCOMPILE_%s]" % name |
| 4197 | if expanding: |
| 4198 | # for expanding, bound parameters or literal values will be |
| 4199 | # rendered per item |
| 4200 | return ret |
| 4201 | |
| 4202 | # otherwise, for non-expanding "literal execute", apply |
| 4203 | # bind casts as determined by the datatype |
| 4204 | if bindparam_type is not None: |
| 4205 | type_impl = bindparam_type._unwrapped_dialect_impl( |
| 4206 | self.dialect |
| 4207 | ) |
| 4208 | if type_impl.render_literal_cast: |
| 4209 | ret = self.render_bind_cast(bindparam_type, type_impl, ret) |
| 4210 | return ret |
| 4211 | elif self.state is CompilerState.COMPILING: |
| 4212 | ret = self.compilation_bindtemplate % {"name": name} |
| 4213 | else: |
| 4214 | ret = self.bindtemplate % {"name": name} |
| 4215 | |
| 4216 | if ( |
no test coverage detected