Render the value of a bind parameter as a quoted literal. This is used for statement sections that do not accept bind parameters on the target driver/database. This should be implemented by subclasses using the quoting services of the DBAPI.
(
self, value: Any, type_: sqltypes.TypeEngine[Any]
)
| 4081 | return self.render_literal_value(value, bindparam.type) |
| 4082 | |
| 4083 | def render_literal_value( |
| 4084 | self, value: Any, type_: sqltypes.TypeEngine[Any] |
| 4085 | ) -> str: |
| 4086 | """Render the value of a bind parameter as a quoted literal. |
| 4087 | |
| 4088 | This is used for statement sections that do not accept bind parameters |
| 4089 | on the target driver/database. |
| 4090 | |
| 4091 | This should be implemented by subclasses using the quoting services |
| 4092 | of the DBAPI. |
| 4093 | |
| 4094 | """ |
| 4095 | |
| 4096 | if value is None and not type_.should_evaluate_none: |
| 4097 | # issue #10535 - handle NULL in the compiler without placing |
| 4098 | # this onto each type, except for "evaluate None" types |
| 4099 | # (e.g. JSON) |
| 4100 | return self.process(elements.Null._instance()) |
| 4101 | |
| 4102 | processor = type_._cached_literal_processor(self.dialect) |
| 4103 | if processor: |
| 4104 | try: |
| 4105 | return processor(value) |
| 4106 | except Exception as e: |
| 4107 | raise exc.CompileError( |
| 4108 | f"Could not render literal value " |
| 4109 | f'"{sql_util._repr_single_value(value)}" ' |
| 4110 | f"with datatype " |
| 4111 | f"{type_}; see parent stack trace for " |
| 4112 | "more detail." |
| 4113 | ) from e |
| 4114 | |
| 4115 | else: |
| 4116 | raise exc.CompileError( |
| 4117 | f"No literal value renderer is available for literal value " |
| 4118 | f'"{sql_util._repr_single_value(value)}" ' |
| 4119 | f"with datatype {type_}" |
| 4120 | ) |
| 4121 | |
| 4122 | def _truncate_bindparam(self, bindparam): |
| 4123 | if bindparam in self.bind_names: |
no test coverage detected