Permalink
Browse files

Cancel SQL export when target server barfs with error 1049 (unknown d…

…atabase). Closes #299
  • Loading branch information...
ansgarbecker committed Nov 25, 2018
1 parent a119aa0 commit b0c0921d974e1b9c0ebd8dcb1b8a764856d73518
Showing with 26 additions and 7 deletions.
  1. +16 −2 source/dbconnection.pas
  2. +10 −5 source/tabletools.pas
@@ -167,7 +167,11 @@ TRowData = class(TObjectList<TCellData>)
TUpdateData = TObjectList<TRowData>;
// Custom exception class for any connection or database related error
EDatabaseError = class(Exception);
EDatabaseError = class(Exception)
public
ErrorCode: Cardinal;
constructor Create(const Msg: string; const ErrorCode: Cardinal=0);
end;
// PLink.exe related
TProcessPipe = class(TObject)
@@ -771,6 +775,16 @@ implementation
uses apphelpers, loginform, change_password;
{ EDatabaseError }
constructor EDatabaseError.Create(const Msg: string; const ErrorCode: Cardinal=0);
begin
Self.ErrorCode := ErrorCode;
inherited Create(Msg);
end;
{ TProcessPipe }
constructor TProcessPipe.Create;
@@ -2448,7 +2462,7 @@ procedure TMySQLConnection.Query(SQL: String; DoStoreResult: Boolean=False; LogC
if QueryStatus <> 0 then begin
// Most errors will show up here, some others slightly later, after mysql_store_result()
Log(lcError, GetLastError);
raise EDatabaseError.Create(GetLastError);
raise EDatabaseError.Create(GetLastError, GetLastErrorCode);
end else begin
// We must call mysql_store_result() + mysql_free_result() to unblock the connection
// See: http://dev.mysql.com/doc/refman/5.0/en/mysql-store-result.html
@@ -83,10 +83,10 @@ TfrmTableTools = class(TFormWithSizeGrip)
menuExportRemoveAutoIncrement: TMenuItem;
comboMatchType: TComboBox;
lblMatchType: TLabel;
pnlDpiHelperMaintenance: TPanel;
pnlDpiHelperFind: TPanel;
pnlDpiHelperExport: TPanel;
pnlDpiHelperTableEdit: TPanel;
pnlDpiHelperMaintenance: TPanel;
pnlDpiHelperFind: TPanel;
pnlDpiHelperExport: TPanel;
pnlDpiHelperTableEdit: TPanel;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
@@ -608,7 +608,12 @@ procedure TfrmTableTools.Execute(Sender: TObject);
on E:EDatabaseError do begin
// The above SQL can easily throw an exception, e.g. if a table is corrupted.
// In such cases we create a dummy row, including the error message
AddNotes(DBObj, 'error', E.Message)
AddNotes(DBObj, 'error', E.Message);
// Cancel further processing on critical errors
if E.ErrorCode = 1049 then begin // "Unknown database"
ErrorDialog(E.Message);
FCancelled := True;
end;
end;
on E:EFCreateError do begin
// Occurs when export output file can not be created

0 comments on commit b0c0921

Please sign in to comment.