MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _run_crud

Method _run_crud

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

Source from the content-addressed store, hash-verified

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