mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-24 04:07:47 +00:00
Fix failing test for batch update policy
This commit is contained in:
1 parent
1e80aecfbd
commit
58263e9b60
2 files changed
+19
-3
No files matched your search
@@ -507,7 +507,12 @@ extension QueryInterfaceRequest where T: MutablePersistableRecord {
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
@discardableResult
|
||||
public func updateAll(_ db: Database, _ assignments: [ColumnAssignment]) throws -> Int {
|
||||
guard let updateStatement = try SQLQueryGenerator(query).makeUpdateStatement(db, assignments) else {
|
||||
let conflictResolution = RowDecoder.persistenceConflictPolicy.conflictResolutionForUpdate
|
||||
guard let updateStatement = try SQLQueryGenerator(query).makeUpdateStatement(
|
||||
db,
|
||||
conflictResolution: conflictResolution,
|
||||
assignments: assignments) else
|
||||
{
|
||||
// database not hit
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -170,7 +170,12 @@ struct SQLQueryGenerator {
|
||||
}
|
||||
|
||||
/// Returns nil if assignments is empty
|
||||
func makeUpdateStatement(_ db: Database, _ assignments: [ColumnAssignment]) throws -> UpdateStatement? {
|
||||
func makeUpdateStatement(
|
||||
_ db: Database,
|
||||
conflictResolution: Database.ConflictResolution,
|
||||
assignments: [ColumnAssignment])
|
||||
throws -> UpdateStatement?
|
||||
{
|
||||
if let groupExpressions = try groupPromise?.resolve(db), !groupExpressions.isEmpty {
|
||||
// Programmer error
|
||||
fatalError("Can't update query with GROUP BY clause")
|
||||
@@ -197,7 +202,13 @@ struct SQLQueryGenerator {
|
||||
|
||||
var context = SQLGenerationContext.queryGenerationContext(aliases: relation.allAliases)
|
||||
|
||||
var sql = try "UPDATE " + relation.source.sql(db, &context)
|
||||
var sql = "UPDATE "
|
||||
|
||||
if conflictResolution != .abort {
|
||||
sql += "OR \(conflictResolution.rawValue) "
|
||||
}
|
||||
|
||||
sql += try relation.source.sql(db, &context)
|
||||
|
||||
let assignmentsSQL = assignments
|
||||
.map({ assignment in
|
||||
|
||||
Reference in new issue
Block a user