MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _emit_post_update_statements

Function _emit_post_update_statements

lib/sqlalchemy/orm/persistence.py:1290–1411  ·  view source on GitHub ↗

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

(
    base_mapper, uowtransaction, mapper, table, update
)

Source from the content-addressed store, hash-verified

1288
1289
1290def _emit_post_update_statements(
1291 base_mapper, uowtransaction, mapper, table, update
1292):
1293 """Emit UPDATE statements corresponding to value lists collected
1294 by _collect_post_update_commands()."""
1295
1296 execution_options = {"compiled_cache": base_mapper._compiled_cache}
1297
1298 needs_version_id = (
1299 mapper.version_id_col is not None
1300 and mapper.version_id_col in mapper._cols_by_table[table]
1301 )
1302
1303 def update_stmt():
1304 clauses = BooleanClauseList._construct_raw(operators.and_)
1305
1306 for col in mapper._pks_by_table[table]:
1307 clauses._append_inplace(
1308 col == sql.bindparam(col._label, type_=col.type)
1309 )
1310
1311 if needs_version_id:
1312 clauses._append_inplace(
1313 mapper.version_id_col
1314 == sql.bindparam(
1315 mapper.version_id_col._label,
1316 type_=mapper.version_id_col.type,
1317 )
1318 )
1319
1320 stmt = table.update().where(clauses)
1321
1322 return stmt
1323
1324 statement = base_mapper._memo(("post_update", table), update_stmt)
1325
1326 if mapper._version_id_has_server_side_value:
1327 statement = statement.return_defaults(mapper.version_id_col)
1328
1329 # execute each UPDATE in the order according to the original
1330 # list of states to guarantee row access order, but
1331 # also group them into common (connection, cols) sets
1332 # to support executemany().
1333 for key, records in groupby(
1334 update,
1335 lambda rec: (rec[3], set(rec[4])), # connection # parameter keys
1336 ):
1337 rows = 0
1338
1339 records = list(records)
1340 connection = key[0]
1341
1342 assert_singlerow = connection.dialect.supports_sane_rowcount
1343 assert_multirow = (
1344 assert_singlerow
1345 and connection.dialect.supports_sane_multi_rowcount
1346 )
1347 allow_executemany = not needs_version_id or assert_multirow

Callers 1

_post_updateFunction · 0.85

Calls 5

_postfetch_post_updateFunction · 0.85
return_defaultsMethod · 0.80
_memoMethod · 0.45
executeMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected