Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions QueryBuilder/Compilers/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down