From 62dbda76ffa51135afaec6d81d5a57d386efdd08 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Fri, 7 Aug 2009 16:41:40 +0000 Subject: [PATCH] SQL completion proposal: Be more exact when detecting the current query and its table aliases, don't mix that up with a potential following or preceding query. See also http://www.heidisql.com/forum/viewtopic.php?p=3419 --- source/main.pas | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/source/main.pas b/source/main.pas index 2f7382d9..c7cba73d 100644 --- a/source/main.pas +++ b/source/main.pas @@ -4456,6 +4456,7 @@ var TokenTypeInt : Integer; Attri : TSynHighlighterAttributes; Editor : TCustomSynEdit; + Queries : TWideStringList; const ItemPattern: WideString = '\image{%d}\hspace{5}\color{clSilver}%s\column{}\color{clWindowText}%s'; @@ -4535,15 +4536,16 @@ begin // spaces are not detected correctly. // 1. find the currently edited sql-statement around the cursor position in synmemo - j := Length(Editor.Text); - for i := Editor.SelStart+1024 downto Editor.SelStart-1024 do - begin - if i > j then - continue; - if i < 1 then + Queries := parsesql(Editor.Text); + j := 0; + for i:=0 to Queries.Count-1 do begin + Inc(j, Length(Queries[i])+1); + if (j >= Editor.SelStart) or (i = Queries.Count-1) then begin + sql := Queries[i]; break; - sql := Editor.Text[i] + sql; + end; end; + FreeAndNil(Queries); // 2. Parse FROM clause to detect relevant table/view, probably aliased rx.ModifierG := True;