From b5e28f43db4ce6d9e0942f20f8b3d06aaa452798 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Wed, 14 Dec 2011 21:11:51 +0000 Subject: [PATCH] Refreshing datagrid result while connection is cut triggers SelectedTableColumns to reset implicitly in ConnectionReady > DBTreeFocusChanged > ParseSelectedTableStructure. Add an explicit Connection.Ping(true) before firing any query in DatagridBeforePaint, and merge code from ParseSelectedTableStructure into DBTreeFocusChanges. Fixes issue #2644. --- source/main.pas | 42 +++++++++++++++++++---------------------- source/table_editor.pas | 1 - source/view.pas | 1 - 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/source/main.pas b/source/main.pas index 7096b8f8..7d93a859 100644 --- a/source/main.pas +++ b/source/main.pas @@ -1015,7 +1015,6 @@ type procedure OnMessageHandler(var Msg: TMsg; var Handled: Boolean); procedure DefaultHandler(var Message); override; procedure SetupSynEditors; - procedure ParseSelectedTableStructure; function AnyGridEnsureFullRow(Grid: TVirtualStringTree; Node: PVirtualNode): Boolean; procedure DataGridEnsureFullRows(Grid: TVirtualStringTree; SelectedOnly: Boolean); function GetEncodingByName(Name: String): TEncoding; @@ -4058,6 +4057,7 @@ begin if DBObj = nil then Exit; Screen.Cursor := crHourglass; + DBObj.Connection.Ping(True); // No data for routines if SelectedTableColumns.Count = 0 then begin @@ -6785,6 +6785,7 @@ procedure TMainForm.DBtreeFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualN var DBObj, PrevDBObj: PDBObject; MainTabToActivate: TTabSheet; + DummyStr: String; begin // Set wanted main tab and call SetMainTab later, when all lists have been invalidated MainTabToActivate := nil; @@ -6828,7 +6829,23 @@ begin Exit; end; end; - ParseSelectedTableStructure; + + // Retrieve columns of current table or view. Mainly used in datagrid. + SelectedTableColumns.Clear; + SelectedTableKeys.Clear; + SelectedTableForeignKeys.Clear; + InvalidateVT(DataGrid, VTREE_NOTLOADED_PURGECACHE, False); + try + case FActiveDbObj.NodeType of + lntTable: + FActiveDbObj.Connection.ParseTableStructure(FActiveDbObj.CreateCode, SelectedTableColumns, SelectedTableKeys, SelectedTableForeignKeys); + lntView: + FActiveDbObj.Connection.ParseViewStructure(FActiveDbObj.CreateCode, FActiveDbObj.Name, SelectedTableColumns, DummyStr, DummyStr, DummyStr, DummyStr); + end; + except on E:EDatabaseError do + ErrorDialog(E.Message); + end; + if not FTreeRefreshInProgress then PlaceObjectEditor(FActiveDbObj); // When a table is clicked in the tree, and the current @@ -6953,27 +6970,6 @@ begin end; -procedure TMainForm.ParseSelectedTableStructure; -var - DummyStr: String; -begin - SelectedTableColumns.Clear; - SelectedTableKeys.Clear; - SelectedTableForeignKeys.Clear; - InvalidateVT(DataGrid, VTREE_NOTLOADED_PURGECACHE, False); - try - case ActiveDbObj.NodeType of - lntTable: - ActiveConnection.ParseTableStructure(ActiveDbObj.CreateCode, SelectedTableColumns, SelectedTableKeys, SelectedTableForeignKeys); - lntView: - ActiveConnection.ParseViewStructure(ActiveDbObj.CreateCode, ActiveDbObj.Name, SelectedTableColumns, DummyStr, DummyStr, DummyStr, DummyStr); - end; - except on E:EDatabaseError do - ErrorDialog(E.Message); - end; -end; - - procedure TMainForm.ConnectionReady(Connection: TDBConnection; Database: String); begin // Manually trigger changed focused tree node, to display the right server vendor diff --git a/source/table_editor.pas b/source/table_editor.pas index 2ae8fefe..e1b276e1 100644 --- a/source/table_editor.pas +++ b/source/table_editor.pas @@ -399,7 +399,6 @@ begin tabALTERcode.TabVisible := DBObject.Name <> ''; Mainform.UpdateEditorTab; Mainform.RefreshTree(DBObject); - Mainform.ParseSelectedTableStructure; Mainform.RefreshHelperNode(HELPERNODE_COLUMNS); ResetModificationFlags; AlterCodeValid := False; diff --git a/source/view.pas b/source/view.pas index 500141d9..391a584a 100644 --- a/source/view.pas +++ b/source/view.pas @@ -178,7 +178,6 @@ begin DBObject.CreateCode := ''; Mainform.UpdateEditorTab; Mainform.RefreshTree(DBObject); - Mainform.ParseSelectedTableStructure; Modified := False; btnSave.Enabled := Modified; btnDiscard.Enabled := Modified;