Skip to content

Commit 0797b24

Browse files
committed
fix: batch DELETE validation failed when deleting multiple rows with PK
1 parent 26bbc97 commit 0797b24

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

TablePro/Core/ChangeTracking/DataChangeManager.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,12 @@ final class DataChangeManager {
682682
)
683683
}
684684

685-
let expectedDeletes = changes.count(where: { $0.type == .delete && deletedRowIndices.contains($0.rowIndex) })
686-
let actualDeletes = statements.count(where: { $0.sql.hasPrefix("DELETE") })
685+
// Validate DELETE coverage: batch DELETE produces 1 statement for N rows when PK exists,
686+
// so count statements != count rows. Instead check that all deletable rows got coverage.
687+
let deletableChanges = changes.filter { $0.type == .delete && deletedRowIndices.contains($0.rowIndex) }
688+
let deletableWithOriginalRow = deletableChanges.filter { $0.originalRow != nil }
687689

688-
if expectedDeletes > 0 && actualDeletes < expectedDeletes {
690+
if !deletableChanges.isEmpty && deletableWithOriginalRow.isEmpty {
689691
throw DatabaseError.queryFailed(
690692
"Cannot save DELETE changes to table '\(tableName)'. " +
691693
"Some rows could not be identified for deletion. Please verify the table data."

0 commit comments

Comments
 (0)