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

Function _emit_update_statements

lib/sqlalchemy/orm/persistence.py:729–960  ·  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

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