From 07964feb7c9e0428af4113c445c411fb36b35e53 Mon Sep 17 00:00:00 2001 From: "rosenfield.albert" Date: Wed, 4 Mar 2009 14:46:36 +0000 Subject: [PATCH] Bugfix: don't use cached data if the connection is gone, as the Delphi TDataSet will croak. Fixes issue #858. --- source/main.pas | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/source/main.pas b/source/main.pas index 07ac45df..579e8921 100644 --- a/source/main.pas +++ b/source/main.pas @@ -890,7 +890,7 @@ type function FetchDbTableList(db: WideString): TDataSet; function RefreshDbTableList(db: WideString): TDataSet; procedure ClearDbTableList(db: WideString); - function DbTableListCached(db: WideString): Boolean; + function DbTableListCachedAndValid(db: WideString): Boolean; procedure ClearAllTableLists; procedure EnsureDatabase; procedure TestVTreeDataArray( P: PVTreeDataArray ); @@ -3966,7 +3966,7 @@ var Unions: TWideStringlist; ListObjectsSQL: WideString; begin - if not DbTableListCached(db) then begin + if not DbTableListCachedAndValid(db) then begin // Not in cache, load table list. OldCursor := Screen.Cursor; Screen.Cursor := crHourGlass; @@ -7088,7 +7088,7 @@ begin NODETYPE_DEFAULT: begin AllListsCached := true; for i := 0 to Databases.Count - 1 do begin - if not DbTableListCached(Databases[i]) then begin + if not DbTableListCachedAndValid(Databases[i]) then begin AllListsCached := false; break; end; @@ -7111,7 +7111,7 @@ begin // Calculate and display the sum of all table sizes in ONE db, if the list is already cached. NODETYPE_DB: begin db := DBtree.Text[Node, 0]; - if not DbTableListCached(db) then + if not DbTableListCachedAndValid(db) then CellText := '' else begin Bytes := 0; @@ -7478,10 +7478,22 @@ begin else Result := MakeInt(d) + MakeInt(i); end; - -function TMainForm.DbTableListCached(db: WideString): Boolean; +function TMainForm.DbTableListCachedAndValid(db: WideString): Boolean; +var + ds: TDataSet; begin Result := CachedTableLists.IndexOf(db) > -1; + if Result then begin + ds := TDataSet(CachedTableLists.Objects[CachedTableLists.IndexOf(db)]); + // Delphi's RTL (TDataSet in DB.pas) throws exceptions right and left + // if the database the dataset(-derivate, aka TZDataSet) came from is + // currently, or has been earlier been, disconnected. Therefore, nuke + // these datasets, they'll have to be reloaded. + if ds.State = dsInactive then begin + ClearDbTableList(db); + Result := False; + end; + end; end; procedure TMainForm.editFilterSearchChange(Sender: TObject);