@@ -285,25 +285,48 @@ protected virtual SqlResult CompileUpdateQuery(Query query)
285285 throw new InvalidOperationException ( "Invalid table expression" ) ;
286286 }
287287
288- var toUpdate = ctx . Query . GetOneComponent < InsertClause > ( "update" , EngineCode ) ;
288+ // check for increment statements
289+ var clause = ctx . Query . GetOneComponent ( "update" , EngineCode ) ;
290+
291+ string wheres ;
292+
293+ if ( clause != null && clause is IncrementClause increment )
294+ {
295+ var column = Wrap ( increment . Column ) ;
296+ var value = Parameter ( ctx , Math . Abs ( increment . Value ) ) ;
297+ var sign = increment . Value >= 0 ? "+" : "-" ;
298+
299+ wheres = CompileWheres ( ctx ) ;
289300
301+ if ( ! string . IsNullOrEmpty ( wheres ) )
302+ {
303+ wheres = " " + wheres ;
304+ }
305+
306+ ctx . RawSql = $ "UPDATE { table } SET { column } = { column } { sign } { value } { wheres } ";
307+
308+ return ctx ;
309+ }
310+
311+
312+ var toUpdate = ctx . Query . GetOneComponent < InsertClause > ( "update" , EngineCode ) ;
290313 var parts = new List < string > ( ) ;
291314
292315 for ( var i = 0 ; i < toUpdate . Columns . Count ; i ++ )
293316 {
294317 parts . Add ( Wrap ( toUpdate . Columns [ i ] ) + " = " + Parameter ( ctx , toUpdate . Values [ i ] ) ) ;
295318 }
296319
297- var where = CompileWheres ( ctx ) ;
320+ var sets = string . Join ( ", " , parts ) ;
298321
299- if ( ! string . IsNullOrEmpty ( where ) )
322+ wheres = CompileWheres ( ctx ) ;
323+
324+ if ( ! string . IsNullOrEmpty ( wheres ) )
300325 {
301- where = " " + where ;
326+ wheres = " " + wheres ;
302327 }
303328
304- var sets = string . Join ( ", " , parts ) ;
305-
306- ctx . RawSql = $ "UPDATE { table } SET { sets } { where } ";
329+ ctx . RawSql = $ "UPDATE { table } SET { sets } { wheres } ";
307330
308331 return ctx ;
309332 }
0 commit comments