From 9710a8363ef5b102bf9e8cc80fccae4e0eeffdd6 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sun, 15 Jan 2012 10:10:12 +0000 Subject: [PATCH] Use different TOP syntax for UPDATE + SELECT queries in MS SQL. Fixes issue #2682. --- source/dbconnection.pas | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/source/dbconnection.pas b/source/dbconnection.pas index 1964888a..66ea0ac8 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -3113,14 +3113,20 @@ end; function TDBConnection.ApplyLimitClause(QueryType, QueryBody: String; Limit, Offset: Cardinal): String; begin Result := QueryType + ' '; - if FParameters.NetTypeGroup = ngMSSQL then - Result := Result + 'TOP '+IntToStr(Limit)+' '; - Result := Result + QueryBody; - if FParameters.NetTypeGroup = ngMySQL then begin - Result := Result + ' LIMIT '; - if Offset > 0 then - Result := Result + IntToStr(Offset) + ', '; - Result := Result + IntToStr(Limit); + case FParameters.NetTypeGroup of + ngMSSQL: begin + if UpperCase(QueryType) = 'UPDATE' then + Result := Result + 'TOP('+IntToStr(Limit)+') ' + else + Result := Result + 'TOP '+IntToStr(Limit)+' '; + Result := Result + QueryBody; + end; + ngMySQL: begin + Result := Result + QueryBody + ' LIMIT '; + if Offset > 0 then + Result := Result + IntToStr(Offset) + ', '; + Result := Result + IntToStr(Limit); + end; end; end;