From ebe36bb0cdd04576164fb83f313432f8bd6d4eeb Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sun, 27 Jan 2013 06:59:37 +0000 Subject: [PATCH] Strip routine body early in ParseRoutineStructure, so later regular expressions don't get confused by keywords in user SQL. Fixes issue #3085. --- source/dbconnection.pas | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/dbconnection.pas b/source/dbconnection.pas index dae3d745..23a0946f 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -3485,6 +3485,12 @@ begin // | SQL SECURITY { DEFINER | INVOKER } // SECURITY_TYPE // | COMMENT 'string' // COMMENT + // Strip body early, so regular expressions don't get confused by keywords + rx.Expression := '\bBEGIN\b'; + if rx.Exec(CreateCode) then begin + Body := TrimLeft(Copy(CreateCode, rx.MatchPos[0], MaxInt)); + Delete(CreateCode, rx.MatchPos[0], MaxInt); + end; rx.Expression := '\bLANGUAGE SQL\b'; if rx.Exec(CreateCode) then Delete(CreateCode, rx.MatchPos[0], rx.MatchLen[0]); @@ -3514,8 +3520,6 @@ begin Comment := StringReplace(rx.Match[1], '''''', '''', [rfReplaceAll]); Delete(CreateCode, rx.MatchPos[0], rx.MatchLen[0]-1); end; - // Tata, remaining code is the routine body - Body := TrimLeft(CreateCode); rx.Free; end;