Skip to content

Commit

Permalink
Fix some suspicious places which can cause exceptions when data tab i…
Browse files Browse the repository at this point in the history
…s open and current connection is being closed. Probably closes #615.
  • Loading branch information
ansgarbecker committed Jun 24, 2019
1 parent a6ea858 commit 5670ba5
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions source/main.pas
Expand Up @@ -2354,10 +2354,16 @@ procedure TMainForm.ConnectionsNotify(Sender: TObject; const Item: TDBConnection
// Connection removed or added // Connection removed or added
case Action of case Action of
cnRemoved, cnExtracted: begin cnRemoved, cnExtracted: begin
// Post pending UPDATE // Post pending UPDATE and release current table with result
Results := GridResult(DataGrid); Results := GridResult(DataGrid);
if Assigned(Results) and Results.Modified then if Assigned(Results) then begin
actDataPostChangesExecute(DataGrid); if Results.Modified then
actDataPostChangesExecute(DataGrid);
if DataGridResult = Results then begin
FreeAndNil(DataGridResult);
DataGridTable := nil;
end;
end;


// Remove result sets which may cause AVs when disconnected // Remove result sets which may cause AVs when disconnected
for Tab in QueryTabs do begin for Tab in QueryTabs do begin
Expand Down Expand Up @@ -2653,6 +2659,7 @@ function TMainForm.HandleUnixTimestampColumn(Sender: TBaseVirtualTree; Column: T
// Shorthand for various places where we would normally have to add all these conditions // Shorthand for various places where we would normally have to add all these conditions
Result := (Sender = DataGrid) Result := (Sender = DataGrid)
and (Column > NoColumn) and (Column > NoColumn)
and (DataGridResult <> nil)
and (DataGridResult.DataType(Column).Category in [dtcInteger, dtcReal]) and (DataGridResult.DataType(Column).Category in [dtcInteger, dtcReal])
and (SelectedTableTimestampColumns.IndexOf(DataGrid.Header.Columns[Column].Text) > -1); and (SelectedTableTimestampColumns.IndexOf(DataGrid.Header.Columns[Column].Text) > -1);
end; end;
Expand Down Expand Up @@ -5681,7 +5688,7 @@ procedure TMainForm.ValidateControls(Sender: TObject);
EnableTimestamp := False; EnableTimestamp := False;
if HasConnection and Assigned(Grid) then begin if HasConnection and Assigned(Grid) then begin
Results := GridResult(Grid); Results := GridResult(Grid);
if Assigned(Grid.FocusedNode) then begin if (Results<>nil) and Assigned(Grid.FocusedNode) then begin
RowNum := Grid.GetNodeData(Grid.FocusedNode); RowNum := Grid.GetNodeData(Grid.FocusedNode);
Results.RecNo := RowNum^; Results.RecNo := RowNum^;
GridHasChanges := Results.Modified or Results.Inserted; GridHasChanges := Results.Modified or Results.Inserted;
Expand Down Expand Up @@ -8445,7 +8452,7 @@ procedure TMainForm.DBtreeFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualN
LogSQL('DBtreeFocusChanged, Node level: '+IntToStr(Sender.GetNodeLevel(Node))+', FTreeRefreshInProgress: '+IntToStr(Integer(FTreeRefreshInProgress)), lcDebug); LogSQL('DBtreeFocusChanged, Node level: '+IntToStr(Sender.GetNodeLevel(Node))+', FTreeRefreshInProgress: '+IntToStr(Integer(FTreeRefreshInProgress)), lcDebug);


// Post pending UPDATE // Post pending UPDATE
if Assigned(DataGridResult) and DataGridResult.Modified then if (DataGridResult<>nil) and DataGridResult.Modified then
actDataPostChangesExecute(DataGrid); actDataPostChangesExecute(DataGrid);


DBObj := Sender.GetNodeData(Node); DBObj := Sender.GetNodeData(Node);
Expand Down Expand Up @@ -9671,8 +9678,8 @@ procedure TMainForm.HandleDataGridAttributes(RefreshingData: Boolean);
if not Assigned(DataGridFocusedCell) then if not Assigned(DataGridFocusedCell) then
DataGridFocusedCell := TStringList.Create; DataGridFocusedCell := TStringList.Create;
// Remember focused node and column for selected table // Remember focused node and column for selected table
if Assigned(DataGrid.FocusedNode) then begin if Assigned(DataGrid.FocusedNode) and (ActiveConnection<>nil) and Assigned(DataGridTable) then begin
KeyName := ActiveConnection.QuoteIdent(DataGridTable.Database)+'.'+ActiveConnection.QuoteIdent(DataGridTable.Name); KeyName := DataGridTable.QuotedDatabase+'.'+DataGridTable.QuotedName;
FocusedCol := ''; FocusedCol := '';
if DataGrid.FocusedColumn > NoColumn then if DataGrid.FocusedColumn > NoColumn then
FocusedCol := DataGrid.Header.Columns[DataGrid.FocusedColumn].Text; FocusedCol := DataGrid.Header.Columns[DataGrid.FocusedColumn].Text;
Expand Down Expand Up @@ -11161,9 +11168,10 @@ function TMainForm.GridResult(Grid: TBaseVirtualTree): TDBQuery;
begin begin
// All grids (data- and query-grids, also host subtabs) are placed directly on a TTabSheet // All grids (data- and query-grids, also host subtabs) are placed directly on a TTabSheet
Result := nil; Result := nil;
if Grid = DataGrid then if Grid = DataGrid then begin
Result := DataGridResult if DataGridResult<>nil then
else if Assigned(Grid) then begin Result := DataGridResult;
end else if Assigned(Grid) then begin
CurrentTab := Grid.Parent as TTabSheet; CurrentTab := Grid.Parent as TTabSheet;
if CurrentTab.Parent = PageControlHost then if CurrentTab.Parent = PageControlHost then
Result := FHostListResults[CurrentTab.PageIndex] Result := FHostListResults[CurrentTab.PageIndex]
Expand Down

0 comments on commit 5670ba5

Please sign in to comment.