(
self, uowcommit, secondary_insert, secondary_update, secondary_delete
)
| 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: |
no test coverage detected