Change the way we count changes in order to support INSTEAD OF triggers

Database.changesCount calls sqlite3_changes(), whose documentation says:

> https://sqlite.org/c3ref/changes.html
> Changes to a view that are intercepted by INSTEAD OF triggers are not counted.

Since we want to support INSTEAD OF triggers well, so that record types can be based on views, we switch to sqlite3_total_changes().
This commit is contained in:
Gwendal Roué authored and Gwendal Roué committed 2025-09-23 17:12:27 +02:00
1 parent 38f5226e95
commit c7bbebc80f
3 files changed
+9 -4

No files matched your search

@@ -635,8 +635,9 @@ extension QueryInterfaceRequest {
@discardableResult
public func deleteAll(_ db: Database) throws -> Int {
let statement = try SQLQueryGenerator(relation: relation).makeDeleteStatement(db)
let prevCount = db.totalChangesCount
try statement.execute()
return db.changesCount
return db.totalChangesCount - prevCount
}
}
@@ -1135,8 +1136,9 @@ extension QueryInterfaceRequest {
// database not hit
return 0
}
let prevCount = db.totalChangesCount
try updateStatement.execute()
return db.changesCount
return db.totalChangesCount - prevCount
}
/// Updates matching rows, and returns the number of updated rows.