Strip comments from current query before trying to detect a table alias. Closes #1753

This commit is contained in:
Ansgar Becker
2023-01-25 18:32:27 +01:00
parent c509a54b03
commit a34b89d37a

View File

@ -6670,7 +6670,7 @@ var
i, j, ImageIndex, ColumnsInList: Integer; i, j, ImageIndex, ColumnsInList: Integer;
Results: TDBQuery; Results: TDBQuery;
DBObjects: TDBObjectList; DBObjects: TDBObjectList;
sql, TableClauses, TableName, LeftPart, Token1, Token2, Token3, Token, Ident: String; CurrentQuery, TableClauses, TableName, LeftPart, Token1, Token2, Token3, Token, Ident: String;
Tables: TStringList; Tables: TStringList;
rx: TRegExpr; rx: TRegExpr;
Start, TokenTypeInt: Integer; Start, TokenTypeInt: Integer;
@ -6796,15 +6796,15 @@ begin
// 1. find currently edited sql query around the cursor position in synmemo // 1. find currently edited sql query around the cursor position in synmemo
if Editor = SynMemoFilter then begin if Editor = SynMemoFilter then begin
// Make sure the below regexp can find structure // Make sure the below regexp can find structure
sql := 'SELECT * FROM '+ActiveDbObj.QuotedName+' WHERE ' + Editor.Text; CurrentQuery := 'SELECT * FROM '+ActiveDbObj.QuotedName+' WHERE ' + Editor.Text;
end else begin end else begin
// In a query tab // In a query tab
Queries := TSQLBatch.Create; Queries := TSQLBatch.Create;
Queries.SQL := Editor.Text; Queries.SQL := Editor.Text;
for Query in Queries do begin for Query in Queries do begin
if (Query.LeftOffset <= Editor.SelStart) and (Editor.SelStart < Query.RightOffset) then begin if (Query.LeftOffset <= Editor.SelStart) and (Editor.SelStart < Query.RightOffset) then begin
sql := Query.SQL; CurrentQuery := Query.SQLWithoutComments;
break; Break;
end; end;
end; end;
Queries.Free; Queries.Free;
@ -6814,7 +6814,7 @@ begin
rx.ModifierG := True; rx.ModifierG := True;
rx.ModifierI := True; rx.ModifierI := True;
rx.Expression := '\b(FROM|INTO|UPDATE)\s+(IGNORE\s+)?(.+)(WHERE|HAVING|ORDER|GROUP)?'; rx.Expression := '\b(FROM|INTO|UPDATE)\s+(IGNORE\s+)?(.+)(WHERE|HAVING|ORDER|GROUP)?';
if rx.Exec(sql) then begin if rx.Exec(CurrentQuery) then begin
TableClauses := rx.Match[3]; TableClauses := rx.Match[3];
// Ensure tables in JOIN clause(s) are splitted by comma // Ensure tables in JOIN clause(s) are splitted by comma
TableClauses := StringReplace(TableClauses, 'JOIN', ',', [rfReplaceAll, rfIgnoreCase]); TableClauses := StringReplace(TableClauses, 'JOIN', ',', [rfReplaceAll, rfIgnoreCase]);