Revert "Allow deleting all rows when passing empty keyvalues dict to simple_delete{_many}"

This reverts commit 7496a37e03.
This commit is contained in:
Andrew Morgan 2022-08-04 14:14:38 +01:00
parent 2f255be9b2
commit ae08e4cd43

View file

@ -2092,9 +2092,7 @@ class DatabasePool:
Args:
table: string giving the table name
keyvalues: dict of column names and values to select the row with. If an
empty dict is passed then no selection clauses are applied. Therefore,
ALL rows will be deleted.
keyvalues: dict of column names and values to select the row with
desc: description of the transaction, for logging and metrics
Returns:
@ -2114,17 +2112,15 @@ class DatabasePool:
Args:
table: string giving the table name
keyvalues: dict of column names and values to select the row with. If an
empty dict is passed then no selection clauses are applied. Therefore,
ALL rows will be deleted.
keyvalues: dict of column names and values to select the row with
Returns:
The number of deleted rows.
"""
sql = "DELETE FROM %s" % (table,)
if keyvalues:
sql += " WHERE %s" % (" AND ".join("%s = ?" % (k,) for k in keyvalues),)
sql = "DELETE FROM %s WHERE %s" % (
table,
" AND ".join("%s = ?" % (k,) for k in keyvalues),
)
txn.execute(sql, list(keyvalues.values()))
return txn.rowcount
@ -2139,19 +2135,18 @@ class DatabasePool:
) -> int:
"""Executes a DELETE query on the named table.
Filters rows if value of `column` is in `iterable`.
Filters rows by if value of `column` is in `iterable`.
Args:
table: string giving the table name
column: column name to test for inclusion against `iterable`
iterable: list of values to match against `column`. NB cannot be a generator
as it may be evaluated multiple times.
keyvalues: dict of column names and values to select the rows with. If an
emtpy dict is passed, this option will have no effect.
keyvalues: dict of column names and values to select the rows with
desc: description of the transaction, for logging and metrics
Returns:
The number of deleted rows.
Number rows deleted
"""
return await self.runInteraction(
desc,
@ -2183,11 +2178,10 @@ class DatabasePool:
column: column name to test for inclusion against `values`
values: values of `column` which choose rows to delete
keyvalues: dict of extra column names and values to select the rows
with. They will be ANDed together with the main predicate. If an
empty dict is passed, this option will have no effect.
with. They will be ANDed together with the main predicate.
Returns:
The number of deleted rows.
Number rows deleted
"""
if not values:
return 0
@ -2201,8 +2195,8 @@ class DatabasePool:
clauses.append("%s = ?" % (key,))
values.append(value)
if clauses:
sql = "%s WHERE %s" % (sql, " AND ".join(clauses))
txn.execute(sql, values)
return txn.rowcount