MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _emit_update_statements

Function _emit_update_statements

lib/sqlalchemy/orm/persistence.py:732–963  ·  view source on GitHub ↗

Emit UPDATE statements corresponding to value lists collected by _collect_update_commands().

(
    base_mapper,
    uowtransaction,
    mapper,
    table,
    update,
    *,
    bookkeeping=True,
    use_orm_update_stmt=None,
    enable_check_rowcount=True,
)

Source from the content-addressed store, hash-verified

730
731
732def _emit_update_statements(
733 base_mapper,
734 uowtransaction,
735 mapper,
736 table,
737 update,
738 *,
739 bookkeeping=True,
740 use_orm_update_stmt=None,
741 enable_check_rowcount=True,
742):
743 """Emit UPDATE statements corresponding to value lists collected
744 by _collect_update_commands()."""
745
746 needs_version_id = (
747 mapper.version_id_col is not None
748 and mapper.version_id_col in mapper._cols_by_table[table]
749 )
750
751 execution_options = {"compiled_cache": base_mapper._compiled_cache}
752
753 def update_stmt(existing_stmt=None):
754 clauses = BooleanClauseList._construct_raw(operators.and_)
755
756 for col in mapper._pks_by_table[table]:
757 clauses._append_inplace(
758 col == sql.bindparam(col._label, type_=col.type)
759 )
760
761 if needs_version_id:
762 clauses._append_inplace(
763 mapper.version_id_col
764 == sql.bindparam(
765 mapper.version_id_col._label,
766 type_=mapper.version_id_col.type,
767 )
768 )
769
770 if existing_stmt is not None:
771 stmt = existing_stmt.where(clauses)
772 else:
773 stmt = table.update().where(clauses)
774 return stmt
775
776 if use_orm_update_stmt is not None:
777 cached_stmt = update_stmt(use_orm_update_stmt)
778
779 else:
780 cached_stmt = base_mapper._memo(("update", table), update_stmt)
781
782 for (
783 (connection, paramkeys, hasvalue, has_all_defaults, has_all_pks),
784 records,
785 ) in groupby(
786 update,
787 lambda rec: (
788 rec[4], # connection
789 set(rec[2]), # set of parameter keys

Callers 1

_save_objFunction · 0.85

Calls 8

update_stmtFunction · 0.85
_postfetchFunction · 0.85
return_defaultsMethod · 0.80
_memoMethod · 0.45
_annotateMethod · 0.45
executeMethod · 0.45
valuesMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected