Skip to content

Commit 6215d19

Browse files
committed
fix: various crash causes, reported in uploaded bug reports
1 parent 519a84a commit 6215d19

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

source/apphelpers.pas

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3525,8 +3525,7 @@ procedure TWinControlHelper.TrySetFocus;
35253525
and CanFocus then
35263526
SetFocus;
35273527
except
3528-
on E:EInvalidOperation do
3529-
SysUtils.Beep;
3528+
SysUtils.Beep;
35303529
end;
35313530
end;
35323531

source/const.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const
9999
MsgUnhandledNetType: String = 'Unhandled connection type (%d)';
100100
MsgUnhandledControl: String = 'Unhandled control in %s';
101101
MsgDisconnect: String = 'Connection to %s closed at %s';
102-
MsgInvalidColumn: String = 'Column #%d not available. Query returned %d columns and %d rows.';
102+
TextInvalidColumn: String = '?';
103103
FILEFILTER_SQLITEDB = '*.sqlite3;*.sqlite;*.db;*.s3db';
104104
FILEEXT_SQLITEDB = 'sqlite3';
105105
PROPOSAL_ITEM_HEIGHT = 18;

source/dbconnection.pas

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8797,8 +8797,9 @@ function TMySQLQuery.Col(Column: Integer; IgnoreErrors: Boolean=False): String;
87978797
end;
87988798

87998799
end;
8800-
end else if not IgnoreErrors then
8801-
Raise EDbError.CreateFmt(_(MsgInvalidColumn), [Column, ColumnCount, RecordCount]);
8800+
end
8801+
else
8802+
Result := TextInvalidColumn;
88028803
end;
88038804

88048805
{$IFDEF HASMSSQL}
@@ -8827,8 +8828,9 @@ function TSqlSrvQuery.Col(Column: Integer; IgnoreErrors: Boolean=False): String;
88278828
else
88288829
Result := '0';
88298830
end
8830-
end else if not IgnoreErrors then
8831-
Raise EDbError.CreateFmt(_(MsgInvalidColumn), [Column, ColumnCount, RecordCount]);
8831+
end
8832+
else
8833+
Result := TextInvalidColumn;
88328834
end;
88338835
{$ENDIF}
88348836

@@ -8849,8 +8851,9 @@ function TPGQuery.Col(Column: Integer; IgnoreErrors: Boolean=False): String;
88498851
else
88508852
Result := Connection.DecodeAPIString(AnsiStr);
88518853
end;
8852-
end else if not IgnoreErrors then
8853-
Raise EDbError.CreateFmt(_(MsgInvalidColumn), [Column, ColumnCount, RecordCount]);
8854+
end
8855+
else
8856+
Result := TextInvalidColumn;
88548857
end;
88558858

88568859

@@ -8863,8 +8866,9 @@ function TSQLiteQuery.Col(Column: Integer; IgnoreErrors: Boolean=False): String;
88638866
end else begin
88648867
Result := FCurrentResults[FRecNoLocal][Column].OldText;
88658868
end;
8866-
end else if not IgnoreErrors then
8867-
Raise EDbError.CreateFmt(_(MsgInvalidColumn), [Column, ColumnCount, RecordCount]);
8869+
end
8870+
else
8871+
Result := TextInvalidColumn;
88688872
end;
88698873

88708874

@@ -8876,8 +8880,9 @@ function TSQLiteQuery.Col(Column: Integer; IgnoreErrors: Boolean=False): String;
88768880
end else begin
88778881
Result := FCurrentResults.Fields[Column].AsString;
88788882
end;
8879-
end else if not IgnoreErrors then
8880-
Raise EDbError.CreateFmt(_(MsgInvalidColumn), [Column, ColumnCount, RecordCount]);
8883+
end
8884+
else
8885+
Result := TextInvalidColumn;
88818886
end;}
88828887

88838888

@@ -8887,12 +8892,11 @@ function TDBQuery.Col(ColumnName: String; IgnoreErrors: Boolean=False): String;
88878892
begin
88888893
// ColumnNames is case insensitive, so we can select wrong cased columns in MariaDB 10.4
88898894
// See #599
8890-
Result := '';
88918895
idx := ColumnNames.IndexOf(ColumnName);
88928896
if idx > -1 then
88938897
Result := Col(idx)
8894-
else if not IgnoreErrors then
8895-
Raise EDbError.CreateFmt(_('Column "%s" not available.'), [ColumnName]);
8898+
else
8899+
Result := TextInvalidColumn;
88968900
end;
88978901

88988902

@@ -8982,8 +8986,9 @@ function TDBQuery.ColAttributes(Column: Integer): TTableColumn;
89828986
i: Integer;
89838987
begin
89848988
Result := nil;
8985-
if (Column < 0) or (Column >= FColumnOrgNames.Count) then
8986-
raise EDbError.CreateFmt(_('Column #%s not available.'), [IntToStr(Column)]);
8989+
if (Column < 0) or (Column >= FColumnOrgNames.Count) then begin
8990+
// Just return nil
8991+
end;
89878992
if FColumns <> nil then begin
89888993
for i:=0 to FColumns.Count-1 do begin
89898994
if FColumns[i].Name = FColumnOrgNames[Column] then begin

source/main.pas

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,8 +1519,10 @@ procedure TMainForm.StatusBarDrawPanel(StatusBar: TStatusBar; Panel: TStatusPane
15191519
2: ImageIndex := 149;
15201520
3: begin
15211521
Conn := ActiveConnection;
1522-
if Conn <> nil then
1522+
if Conn <> nil then try
15231523
ImageIndex := Conn.Parameters.ImageIndex;
1524+
except
1525+
end;
15241526
end;
15251527
5: ImageIndex := 190;
15261528
6: begin
@@ -4238,7 +4240,7 @@ procedure TMainForm.SessionConnect(Sender: TObject);
42384240
for i:=High(FTreeClickHistory) downto Low(FTreeClickHistory) do begin
42394241
if FTreeClickHistory[i] <> nil then begin
42404242
DBObj := DBtree.GetNodeData(FTreeClickHistory[i]);
4241-
if DBObj = nil then // Session disconnected
4243+
if (DBObj = nil) or (DBObj.Connection = nil) or (not DBObj.Connection.Active) then // Session disconnected
42424244
Break;
42434245
if DBObj.Connection.Parameters.SessionPath = SessionPath then begin
42444246
Node := FTreeClickHistory[i];
@@ -9474,6 +9476,8 @@ procedure TMainForm.DBtreeGetImageIndex(Sender: TBaseVirtualTree; Node:
94749476
if Column > 0 then
94759477
Exit;
94769478
DBObj := Sender.GetNodeData(Node);
9479+
if not Assigned(DBObj) then
9480+
Exit;
94779481
case Kind of
94789482
ikNormal, ikSelected:
94799483
ImageIndex := DBObj.ImageIndex;

0 commit comments

Comments
 (0)