From 01b37b64735c95bcf56eac812632c975704bc6af Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Wed, 1 Jan 2020 11:53:52 +0100 Subject: [PATCH] Issue #12: Fix TDBConnection.ApplyLimitClause for SQLite, which does not support a LIMIT clause in UPDATE/DELETE statements --- source/dbconnection.pas | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source/dbconnection.pas b/source/dbconnection.pas index bf9e75c0..ef107fa9 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -6090,7 +6090,7 @@ begin Result := Result + 'TOP '+IntToStr(Limit)+' '; Result := Result + QueryBody; end; - ngMySQL, ngSQLite: begin + ngMySQL: begin Result := Result + QueryBody + ' LIMIT '; if Offset > 0 then Result := Result + IntToStr(Offset) + ', '; @@ -6104,6 +6104,17 @@ begin end else Result := Result + QueryBody; end; + ngSQLite: begin + // LIMIT supported only in SELECT queries + // For UPDATEs and DELETEs only if we would compile sqlite library with SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile flag + Result := Result + QueryBody; + if Result.StartsWith('SELECT') then begin + Result := Result + ' LIMIT '; + if Offset > 0 then + Result := Result + IntToStr(Offset) + ', '; + Result := Result + IntToStr(Limit); + end; + end; end; end;