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

Method _run_crud

lib/sqlalchemy/orm/dependency.py:1199–1258  ·  view source on GitHub ↗
(
        self, uowcommit, secondary_insert, secondary_update, secondary_delete
    )

Source from the content-addressed store, hash-verified

1197 )
1198
1199 def _run_crud(
1200 self, uowcommit, secondary_insert, secondary_update, secondary_delete
1201 ):
1202 connection = uowcommit.transaction.connection(self.mapper)
1203
1204 if secondary_delete:
1205 associationrow = secondary_delete[0]
1206 statement = self.secondary.delete().where(
1207 sql.and_(
1208 *[
1209 c == sql.bindparam(c.key, type_=c.type)
1210 for c in self.secondary.c
1211 if c.key in associationrow
1212 ]
1213 )
1214 )
1215 result = connection.execute(statement, secondary_delete)
1216
1217 if (
1218 result.supports_sane_multi_rowcount()
1219 ) and result.rowcount != len(secondary_delete):
1220 raise exc.StaleDataError(
1221 "DELETE statement on table '%s' expected to delete "
1222 "%d row(s); Only %d were matched."
1223 % (
1224 self.secondary.description,
1225 len(secondary_delete),
1226 result.rowcount,
1227 )
1228 )
1229
1230 if secondary_update:
1231 associationrow = secondary_update[0]
1232 statement = self.secondary.update().where(
1233 sql.and_(
1234 *[
1235 c == sql.bindparam("old_" + c.key, type_=c.type)
1236 for c in self.secondary.c
1237 if c.key in associationrow
1238 ]
1239 )
1240 )
1241 result = connection.execute(statement, secondary_update)
1242
1243 if (
1244 result.supports_sane_multi_rowcount()
1245 ) and result.rowcount != len(secondary_update):
1246 raise exc.StaleDataError(
1247 "UPDATE statement on table '%s' expected to update "
1248 "%d row(s); Only %d were matched."
1249 % (
1250 self.secondary.description,
1251 len(secondary_update),
1252 result.rowcount,
1253 )
1254 )
1255
1256 if secondary_insert:

Callers 2

process_deletesMethod · 0.95
process_savesMethod · 0.95

Calls 8

connectionMethod · 0.45
whereMethod · 0.45
deleteMethod · 0.45
and_Method · 0.45
executeMethod · 0.45
updateMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected