From 6a823b23267bebf4ab7150848fd169e86aff4c92 Mon Sep 17 00:00:00 2001 From: Sandip Bantawa Date: Tue, 10 Jan 2023 05:04:05 +0000 Subject: [PATCH] Added joins on CompileUpdateQuery for issue #637 --- QueryBuilder/Compilers/Compiler.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/QueryBuilder/Compilers/Compiler.cs b/QueryBuilder/Compilers/Compiler.cs index aa15c789..ba501d1e 100644 --- a/QueryBuilder/Compilers/Compiler.cs +++ b/QueryBuilder/Compilers/Compiler.cs @@ -346,6 +346,7 @@ protected virtual SqlResult CompileUpdateQuery(Query query) var clause = ctx.Query.GetOneComponent("update", EngineCode); string wheres; + string joins; if (clause != null && clause is IncrementClause increment) { @@ -354,13 +355,14 @@ protected virtual SqlResult CompileUpdateQuery(Query query) var sign = increment.Value >= 0 ? "+" : "-"; wheres = CompileWheres(ctx); + joins = CompileJoins(ctx); if (!string.IsNullOrEmpty(wheres)) { wheres = " " + wheres; } - ctx.RawSql = $"UPDATE {table} SET {column} = {column} {sign} {value}{wheres}"; + ctx.RawSql = $"UPDATE {table} SET {column} = {column} {sign} {value} FROM {table}{joins}{wheres}"; return ctx; } @@ -377,13 +379,14 @@ protected virtual SqlResult CompileUpdateQuery(Query query) var sets = string.Join(", ", parts); wheres = CompileWheres(ctx); + joins = CompileJoins(ctx); if (!string.IsNullOrEmpty(wheres)) { wheres = " " + wheres; } - ctx.RawSql = $"UPDATE {table} SET {sets}{wheres}"; + ctx.RawSql = $"UPDATE {table} SET {sets} FROM {table}{joins}{wheres}"; return ctx; }