Skip to content
Permalink
Browse files

Fix implicit use of quoted schema (database)

  • Loading branch information
zilzila authored and ansgarbecker committed Feb 28, 2020
1 parent 74ea786 commit 31ab977b224015e2502844d98cbb714a18d70b47
Showing with 38 additions and 26 deletions.
  1. +7 −1 source/dbconnection.pas
  2. +31 −25 source/main.pas
@@ -837,10 +837,11 @@ TIdentToken = class(TObject)
FValue: string;
FIsQuoted: Boolean;
FConn: TDBConnection;
procedure SetValue(const Value: string);
public
constructor Create(AConn: TDBConnection);
property Original: string read FOriginal;
property Value: string read FValue;
property Value: string read FValue write SetValue;
property IsQuoted: Boolean read FIsQuoted;
procedure Parse(Text: string);
end;
@@ -9294,6 +9295,11 @@ constructor TIdentToken.Create(AConn: TDBConnection);
FConn := AConn;
end;

procedure TIdentToken.SetValue(const Value: string);
begin
FValue := Value;
end;

procedure TIdentToken.Parse(Text: string);
var
QuoteChar: Char;
@@ -5987,18 +5987,20 @@ procedure TMainForm.SynCompletionProposalExecute(Kind: SynCompletionType;
Obj: TDBObject;
begin
if Ident.Token1.Value = '' then
Ident.Token1.Parse(Conn.QuoteIdent(Conn.Database, False));

DBObjects := Conn.GetDBObjects(Ident.Token1.Value);
for Obj in DBObjects do begin
if (Obj.Name = Ident.Token2.Value) and (Obj.NodeType in [lntTable, lntView]) then begin
Columns := Obj.TableColumns;
for Col in Columns do begin
Proposal.InsertList.Add(Col.Name);
Proposal.ItemList.Add(Format(SYNCOMPLETION_PATTERN, [ICONINDEX_FIELD, LowerCase(Col.DataType.Name), Col.Name, '']) );
Ident.Token1.Value := Conn.Database;

if Ident.Token1.Value <> '' then begin
DBObjects := Conn.GetDBObjects(Ident.Token1.Value);
for Obj in DBObjects do begin
if (Obj.Name = Ident.Token2.Value) and (Obj.NodeType in [lntTable, lntView]) then begin
Columns := Obj.TableColumns;
for Col in Columns do begin
Proposal.InsertList.Add(Col.Name);
Proposal.ItemList.Add(Format(SYNCOMPLETION_PATTERN, [ICONINDEX_FIELD, LowerCase(Col.DataType.Name), Col.Name, '']) );
end;
Columns.Free;
break;
end;
Columns.Free;
break;
end;
end;
end;
@@ -6118,21 +6120,25 @@ procedure TMainForm.SynCompletionProposalExecute(Kind: SynCompletionType;
FreeAndNil(TableIdent);
end;

if (FieldIdent.Token1.Value <> '') or (FieldIdent.Token2.Value <> '') then
AddColumns(FieldIdent);

if FieldIdent.Token1.Value = '' then begin
i := Conn.AllDatabases.IndexOf(FieldIdent.Token2.Value);
if i > -1 then begin
// Tables from specific database
Screen.Cursor := crHourGlass;
DBObjects := Conn.GetDBObjects(Conn.AllDatabases[i]);
Conn.PrefetchCreateCode(DBObjects);
for j:=0 to DBObjects.Count-1 do
AddTable(DBObjects[j]);
Conn.PurgePrefetchResults;
Screen.Cursor := crDefault;
// Token2 - schema or table
if FieldIdent.Token2.Value <> '' then begin
// Token2 - schema
if FieldIdent.Token1.Value = '' then begin
i := Conn.AllDatabases.IndexOf(FieldIdent.Token2.Value);
if i > -1 then begin
// Tables from specific database
Screen.Cursor := crHourGlass;
DBObjects := Conn.GetDBObjects(Conn.AllDatabases[i]);
Conn.PrefetchCreateCode(DBObjects);
for j:=0 to DBObjects.Count-1 do
AddTable(DBObjects[j]);
Conn.PurgePrefetchResults;
Screen.Cursor := crDefault;
end;
end;

// Token2 - table
AddColumns(FieldIdent);
end;

if FieldIdent.Token2.Value = '' then begin

0 comments on commit 31ab977

Please sign in to comment.
You can’t perform that action at this time.