MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _emit_delete_statements

Function _emit_delete_statements

lib/sqlalchemy/orm/persistence.py:1414–1510  ·  view source on GitHub ↗

Emit DELETE statements corresponding to value lists collected by _collect_delete_commands().

(
    base_mapper, uowtransaction, mapper, table, delete
)

Source from the content-addressed store, hash-verified

1412
1413
1414def _emit_delete_statements(
1415 base_mapper, uowtransaction, mapper, table, delete
1416):
1417 """Emit DELETE statements corresponding to value lists collected
1418 by _collect_delete_commands()."""
1419
1420 need_version_id = (
1421 mapper.version_id_col is not None
1422 and mapper.version_id_col in mapper._cols_by_table[table]
1423 )
1424
1425 def delete_stmt():
1426 clauses = BooleanClauseList._construct_raw(operators.and_)
1427
1428 for col in mapper._pks_by_table[table]:
1429 clauses._append_inplace(
1430 col == sql.bindparam(col.key, type_=col.type)
1431 )
1432
1433 if need_version_id:
1434 clauses._append_inplace(
1435 mapper.version_id_col
1436 == sql.bindparam(
1437 mapper.version_id_col.key, type_=mapper.version_id_col.type
1438 )
1439 )
1440
1441 return table.delete().where(clauses)
1442
1443 statement = base_mapper._memo(("delete", table), delete_stmt)
1444 for connection, recs in groupby(delete, lambda rec: rec[1]): # connection
1445 del_objects = [params for params, connection in recs]
1446
1447 execution_options = {"compiled_cache": base_mapper._compiled_cache}
1448 expected = len(del_objects)
1449 rows_matched = -1
1450 only_warn = False
1451
1452 if (
1453 need_version_id
1454 and not connection.dialect.supports_sane_multi_rowcount
1455 ):
1456 if connection.dialect.supports_sane_rowcount:
1457 rows_matched = 0
1458 # execute deletes individually so that versioned
1459 # rows can be verified
1460 for params in del_objects:
1461 c = connection.execute(
1462 statement, params, execution_options=execution_options
1463 )
1464 rows_matched += c.rowcount
1465 else:
1466 util.warn(
1467 "Dialect %s does not support deleted rowcount "
1468 "- versioning cannot be verified."
1469 % connection.dialect.dialect_description
1470 )
1471 connection.execute(

Callers 1

_delete_objFunction · 0.85

Calls 3

_memoMethod · 0.45
executeMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected