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

Function _handle_values_anonymous_param

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

Source from the content-addressed store, hash-verified

480
481
482def _handle_values_anonymous_param(compiler, col, value, name, **kw):
483 # the insert() and update() constructs as of 1.4 will now produce anonymous
484 # bindparam() objects in the values() collections up front when given plain
485 # literal values. This is so that cache key behaviors, which need to
486 # produce bound parameters in deterministic order without invoking any
487 # compilation here, can be applied to these constructs when they include
488 # values() (but not yet multi-values, which are not included in caching
489 # right now).
490 #
491 # in order to produce the desired "crud" style name for these parameters,
492 # which will also be targetable in engine/default.py through the usual
493 # conventions, apply our desired name to these unique parameters by
494 # populating the compiler truncated names cache with the desired name,
495 # rather than having
496 # compiler.visit_bindparam()->compiler._truncated_identifier make up a
497 # name. Saves on call counts also.
498
499 # for INSERT/UPDATE that's a CTE, we don't need names to match to
500 # external parameters and these would also conflict in the case where
501 # multiple insert/update are combined together using CTEs
502 is_cte = "visiting_cte" in kw
503
504 if (
505 not is_cte
506 and value.unique
507 and isinstance(value.key, elements._truncated_label)
508 ):
509 compiler.truncated_names[("bindparam", value.key)] = name
510
511 if value.type._isnull:
512 # either unique parameter, or other bound parameters that were
513 # passed in directly
514 # set type to that of the column unconditionally
515 value = value._with_binary_element_type(col.type)
516
517 return value._compiler_dispatch(compiler, **kw)
518
519
520def _key_getters_for_crud_column(

Callers 2

_append_param_parameterFunction · 0.85

Calls 2

_compiler_dispatchMethod · 0.45

Tested by

no test coverage detected