mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
ColumnAssignment that does nothing
A cool upsert feature is to overwrite an existing value in case of conflict, but another cool upsert feature is to NOT overwrite an existing value. This commit makes it possible to create a ColumnAssignement that does nothing.
This commit is contained in:
1 parent
2a5626efea
commit
c6657b7063
2 files changed
+29
-21
No files matched your search
@@ -288,12 +288,6 @@ struct SQLQueryGenerator: Refinable {
|
||||
selection: selection)
|
||||
}
|
||||
|
||||
// Check for empty assignments after all programmer errors have
|
||||
// been checked.
|
||||
if assignments.isEmpty {
|
||||
return nil
|
||||
}
|
||||
|
||||
let context = SQLGenerationContext(db, aliases: relation.allAliases, ctes: relation.ctes)
|
||||
|
||||
var sql = try commonTableExpressionsPrefix(context)
|
||||
@@ -305,10 +299,13 @@ struct SQLQueryGenerator: Refinable {
|
||||
|
||||
sql += try relation.source.sql(context)
|
||||
|
||||
sql += " SET "
|
||||
sql += try assignments
|
||||
.map { try $0.sql(context) }
|
||||
let updateSQL = try assignments
|
||||
.compactMap { try $0.sql(context) }
|
||||
.joined(separator: ", ")
|
||||
if updateSQL.isEmpty {
|
||||
return nil
|
||||
}
|
||||
sql += " SET \(updateSQL)"
|
||||
|
||||
if let filter = try relation.filterPromise?.resolve(db) {
|
||||
sql += " WHERE "
|
||||
@@ -351,12 +348,6 @@ struct SQLQueryGenerator: Refinable {
|
||||
selection: [any SQLSelectable])
|
||||
throws -> Statement?
|
||||
{
|
||||
// Check for empty assignments after all programmer errors have
|
||||
// been checked.
|
||||
if assignments.isEmpty {
|
||||
return nil
|
||||
}
|
||||
|
||||
let tableName = relation.source.tableName
|
||||
let alias = TableAlias(tableName: tableName)
|
||||
let context = SQLGenerationContext(db, aliases: [alias])
|
||||
@@ -374,10 +365,13 @@ struct SQLQueryGenerator: Refinable {
|
||||
sql += tableName.quotedDatabaseIdentifier
|
||||
|
||||
// SET column = value...
|
||||
sql += " SET "
|
||||
sql += try assignments
|
||||
.map { try $0.sql(context) }
|
||||
let updateSQL = try assignments
|
||||
.compactMap { try $0.sql(context) }
|
||||
.joined(separator: ", ")
|
||||
if updateSQL.isEmpty {
|
||||
return nil
|
||||
}
|
||||
sql += " SET \(updateSQL)"
|
||||
|
||||
// WHERE id IN (SELECT id FROM ...)
|
||||
sql += " WHERE "
|
||||
|
||||
Reference in new issue
Block a user