MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _handle_values_anonymous_param

Function _handle_values_anonymous_param

lib/sqlalchemy/sql/crud.py:545–580  ·  view source on GitHub ↗
(compiler, col, value, name, **kw)

Source from the content-addressed store, hash-verified

543
544
545def _handle_values_anonymous_param(compiler, col, value, name, **kw):
546 # the insert() and update() constructs as of 1.4 will now produce anonymous
547 # bindparam() objects in the values() collections up front when given plain
548 # literal values. This is so that cache key behaviors, which need to
549 # produce bound parameters in deterministic order without invoking any
550 # compilation here, can be applied to these constructs when they include
551 # values() (but not yet multi-values, which are not included in caching
552 # right now).
553 #
554 # in order to produce the desired "crud" style name for these parameters,
555 # which will also be targetable in engine/default.py through the usual
556 # conventions, apply our desired name to these unique parameters by
557 # populating the compiler truncated names cache with the desired name,
558 # rather than having
559 # compiler.visit_bindparam()->compiler._truncated_identifier make up a
560 # name. Saves on call counts also.
561
562 # for INSERT/UPDATE that's a CTE, we don't need names to match to
563 # external parameters and these would also conflict in the case where
564 # multiple insert/update are combined together using CTEs
565 is_cte = "visiting_cte" in kw
566
567 if (
568 not is_cte
569 and value.unique
570 and isinstance(value.key, elements._truncated_label)
571 ):
572 compiler.truncated_names[("bindparam", value.key)] = name
573
574 if value.type._isnull:
575 # either unique parameter, or other bound parameters that were
576 # passed in directly
577 # set type to that of the column unconditionally
578 value = value._with_binary_element_type(col.type)
579
580 return value._compiler_dispatch(compiler, **kw)
581
582
583def _key_getters_for_crud_column(

Callers 2

_append_param_parameterFunction · 0.85

Calls 2

_compiler_dispatchMethod · 0.45

Tested by

no test coverage detected