MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / render_literal_value

Method render_literal_value

lib/sqlalchemy/sql/compiler.py:3904–3941  ·  view source on GitHub ↗

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]
    )

Source from the content-addressed store, hash-verified

3902 return self.render_literal_value(value, bindparam.type)
3903
3904 def render_literal_value(
3905 self, value: Any, type_: sqltypes.TypeEngine[Any]
3906 ) -> str:
3907 """Render the value of a bind parameter as a quoted literal.
3908
3909 This is used for statement sections that do not accept bind parameters
3910 on the target driver/database.
3911
3912 This should be implemented by subclasses using the quoting services
3913 of the DBAPI.
3914
3915 """
3916
3917 if value is None and not type_.should_evaluate_none:
3918 # issue #10535 - handle NULL in the compiler without placing
3919 # this onto each type, except for "evaluate None" types
3920 # (e.g. JSON)
3921 return self.process(elements.Null._instance())
3922
3923 processor = type_._cached_literal_processor(self.dialect)
3924 if processor:
3925 try:
3926 return processor(value)
3927 except Exception as e:
3928 raise exc.CompileError(
3929 f"Could not render literal value "
3930 f'"{sql_util._repr_single_value(value)}" '
3931 f"with datatype "
3932 f"{type_}; see parent stack trace for "
3933 "more detail."
3934 ) from e
3935
3936 else:
3937 raise exc.CompileError(
3938 f"No literal value renderer is available for literal value "
3939 f'"{sql_util._repr_single_value(value)}" '
3940 f"with datatype {type_}"
3941 )
3942
3943 def _truncate_bindparam(self, bindparam):
3944 if bindparam in self.bind_names:

Calls 3

processMethod · 0.45
_instanceMethod · 0.45

Tested by

no test coverage detected