Skip to content
Permalink
Browse files

Revert non working modifications for auto completion. Closes #917 and…

… reverts #914
  • Loading branch information
ansgarbecker committed Mar 1, 2020
1 parent f1b72b7 commit 919be1d355da38e8c2e50d39b3846d737ec56a4d
Showing with 73 additions and 271 deletions.
  1. +0 −182 source/dbconnection.pas
  2. +73 −89 source/main.pas
@@ -472,7 +472,6 @@ TDBConnection = class(TComponent)
property LastErrorMsg: String read GetLastErrorMsg;
property ServerOS: String read FServerOS;
property ServerVersionUntouched: String read FServerVersionUntouched;
property QuoteChar: Char read FQuoteChar;
property QuoteChars: String read FQuoteChars;
function ServerVersionStr: String;
function ServerVersionInt: Integer;
@@ -831,46 +830,6 @@ TSQLiteQuery = class(TDBQuery)
function TableName(Column: Integer): String; overload; override;
end;

TIdentToken = class(TObject)
private
FOriginal: string;
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 write SetValue;
property IsQuoted: Boolean read FIsQuoted;
procedure Parse(Text: string);
end;

TIdent = class(TObject)
private
FToken1: TIdentToken;
FToken2: TIdentToken;
FToken3: TIdentToken;
FConn: TDBConnection;
public
constructor Create(AConn: TDBConnection);
destructor Destroy; override;
property Token1: TIdentToken read FToken1;
property Token2: TIdentToken read FToken2;
property Token3: TIdentToken read FToken3;
procedure Parse(Text: string); virtual; abstract;
end;

TFieldIdent = class(TIdent)
public
procedure Parse(Text: string); override;
end;

TTableIdent = class(TIdent)
public
procedure Parse(Text: string); override;
end;

function mysql_authentication_dialog_ask(
Handle: PMYSQL;
_type: Integer;
@@ -9198,145 +9157,4 @@ function mysql_authentication_dialog_ask;




{ TIdent }

constructor TIdent.Create(AConn: TDBConnection);
begin
FConn := AConn;
FToken1 := TIdentToken.Create(FConn);
FToken2 := TIdentToken.Create(FConn);
FToken3 := TIdentToken.Create(FConn);
end;

destructor TIdent.Destroy;
begin
FreeAndNil(FToken1);
FreeAndNil(FToken2);
FreeAndNil(FToken3);
inherited;
end;




{ TFieldIdent }

procedure TFieldIdent.Parse(Text: string);
var
rx: TRegExpr;
begin
rx := TRegExpr.Create;
rx.ModifierI := True;
rx.ModifierG := True; // required (default)
rx.ModifierX := True; // required (if rx.Expression contains whitespaces, formatting etc)

// Find token1.token2.token3, while cursor is somewhere in token3
rx.Expression := ''
+ '('
+ ' ([^\s,)(=.]+)'
+ '|'
+ ' ([^\s,)(=."]+ | "([^"]|"")+") \.'
+ ' ([^\s,)(=.]+)?'
+ '|'
+ ' ([^\s,)(=."]+ | "([^"]|"")+") \.'
+ ' ([^\s,)(=."]+ | "([^"]|"")+") \.'
+ ' ([^\s,)(=.]+)?'
+ ')$';

rx.Expression := ReplaceStr(rx.Expression, '"', '\' + FConn.QuoteChar);

if rx.Exec(Trim(Text)) then begin
// Keyword|Schema|Table|Column|Proc|etc
if rx.Match[2] <> '' then begin
Token1.Parse('');
Token2.Parse('');
Token3.Parse(rx.Match[2]);
// Schema.Table|Table.Column
end else if rx.Match[3] <> '' then begin
Token1.Parse('');
Token2.Parse(rx.Match[3]);
Token3.Parse(rx.Match[5]);
// Schema.Table.Column
end else if rx.Match[6] <> '' then begin
Token1.Parse(rx.Match[6]);
Token2.Parse(rx.Match[8]);
Token3.Parse(rx.Match[10]);
end;
end;

FreeAndNil(rx);
end;




{ TTableIdent }

procedure TTableIdent.Parse(Text: string);
var
rx: TRegExpr;
begin
rx := TRegExpr.Create;
rx.ModifierI := True;
rx.ModifierG := True; // required (default)
rx.ModifierX := True; // required (if rx.Expression contains whitespaces, formatting etc)

// Find Token1.Token2[ as ]Token3
rx.Expression := ''
+ '(([^\s,)(=."]+ | "([^"]|"")+") \.)?'
+ ' ([^\s,)(=."]+ | "([^"]|"")+") \s*(AS)??\s*'
+ ' ([^\s,)(=."]+ | "([^"]|"")+")?$';

rx.Expression := ReplaceStr(rx.Expression, '"', '\' + FConn.QuoteChar);

if rx.Exec(Trim(Text)) then begin
Token1.Parse(rx.Match[2]);
Token2.Parse(rx.Match[4]);
Token3.Parse(rx.Match[7]);
end;

FreeAndNil(rx);
end;




{ TIdentToken }

constructor TIdentToken.Create(AConn: TDBConnection);
begin
FConn := AConn;
end;

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

procedure TIdentToken.Parse(Text: string);
var
QuoteChar: Char;
begin
FOriginal := Text;
FValue := Trim(Text);

if FValue = '' then begin
FIsQuoted := False;
exit;
end;

QuoteChar := FConn.QuoteChar;
FIsQuoted := (Length(FValue) > 2) and (FValue[1] = QuoteChar) and (FValue[Length(FValue)] = QuoteChar);

// UnQuote ident without deleting all TDBConnection.FQuoteChars
if FIsQuoted then begin
FValue := Copy(FValue, 2, Length(FValue) - 2);
FValue := StringReplace(FValue, QuoteChar + QuoteChar, QuoteChar, [rfReplaceAll]);
end;

if (not FIsQuoted) and (FConn is TPgConnection) then
FValue := LowerCase(FValue);
end;

end.

0 comments on commit 919be1d

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