Skip to content
Permalink
Browse files

Cache the myriad of SELECT 123::regclass queries in a hash table on t…

…he PostgreSQL connection object. Closes #249, closes #538
  • Loading branch information...
ansgarbecker committed May 18, 2019
1 parent 54f7b77 commit 178d92e27382dd120e50c876d9caa39ba739005c
Showing with 13 additions and 1 deletion.
  1. +13 −1 source/dbconnection.pas
@@ -86,6 +86,8 @@ TDBObjectDropComparer = class(TComparer<TDBObject>)
// General purpose editing status flag
TEditingStatus = (esUntouched, esModified, esDeleted, esAddedUntouched, esAddedModified, esAddedDeleted);

TIntStringPairs = TDictionary<Integer, String>;

TColumnDefaultType = (cdtNothing, cdtText, cdtNull, cdtAutoInc, cdtExpression);

// Column object, many of them in a TObjectList
@@ -342,6 +344,7 @@ TDBConnection = class(TComponent)
FKeepAliveTimer: TTimer;
FFavorites: TStringList;
FPrefetchResults: TDBQueryList;
FRegClasses: TIntStringPairs;
procedure SetActive(Value: Boolean); virtual; abstract;
procedure DoBeforeConnect; virtual;
procedure DoAfterConnect; virtual;
@@ -449,6 +452,7 @@ TDBConnection = class(TComponent)
property LockedByThread: TThread read FLockedByThread write SetLockedByThread;
property Datatypes: TDBDataTypeArray read FDatatypes;
property Favorites: TStringList read FFavorites;
property RegClasses: TIntStringPairs read FRegClasses;
function GetLockedTableCount(db: String): Integer;
function IdentifierEquals(Ident1, Ident2: String): Boolean;
published
@@ -1498,6 +1502,8 @@ constructor TDBConnection.Create(AOwner: TComponent);
FCurrentUserHostCombination := '';
FKeepAliveTimer := TTimer.Create(Self);
FFavorites := TStringList.Create;
// PG only, cache for 123::regclass queries:
FRegClasses := TIntStringPairs.Create;
end;


@@ -1548,6 +1554,7 @@ destructor TDBConnection.Destroy;
ClearCache(True);
FKeepAliveTimer.Free;
FFavorites.Free;
FRegClasses.Free;
inherited;
end;

@@ -7063,7 +7070,12 @@ function TPGQuery.TableName: String;
Result := '';
for i:=0 to ColumnCount-1 do begin
FieldTypeOID := PQftable(FCurrentResults, i);
Result := FConnection.GetVar('SELECT '+IntToStr(FieldTypeOID)+'::regclass');
if not FConnection.RegClasses.ContainsKey(FieldTypeOID) then begin
Result := FConnection.GetVar('SELECT '+IntToStr(FieldTypeOID)+'::regclass');
FConnection.RegClasses.Add(FieldTypeOID, Result);
end else begin
FConnection.RegClasses.TryGetValue(FieldTypeOID, Result);
end;
if Result <> '' then
Break;
end;

0 comments on commit 178d92e

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