Fix crash when database lib config is not valid
This commit is contained in:
parent
f169f7a009
commit
7a7a23c83a
|
@ -96,6 +96,7 @@ void DIALOG_DATABASE_LIB_SETTINGS::OnBtnTest( wxCommandEvent& aEvent )
|
|||
if( m_plugin->TestConnection( &errorMsg ) )
|
||||
{
|
||||
m_stConnectionTestStatus->SetLabel( _( "Connected to database successfully" ) );
|
||||
m_stConnectionTestStatus->SetToolTip( wxEmptyString );
|
||||
|
||||
wxCommandEvent dummy;
|
||||
OnBtnReloadConfig( dummy );
|
||||
|
@ -104,6 +105,7 @@ void DIALOG_DATABASE_LIB_SETTINGS::OnBtnTest( wxCommandEvent& aEvent )
|
|||
{
|
||||
m_stConnectionTestStatus->SetLabel( wxString::Format( _( "Database connection failed: %s" ),
|
||||
errorMsg ) );
|
||||
m_stConnectionTestStatus->SetToolTip( errorMsg );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ DIALOG_DATABASE_LIB_SETTINGS_BASE::DIALOG_DATABASE_LIB_SETTINGS_BASE( wxWindow*
|
|||
m_btnTest = new wxButton( sbSizer4->GetStaticBox(), wxID_ANY, _("Test"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
bSizer5->Add( m_btnTest, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
||||
|
||||
m_stConnectionTestStatus = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
||||
m_stConnectionTestStatus = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_MIDDLE );
|
||||
m_stConnectionTestStatus->Wrap( -1 );
|
||||
bSizer5->Add( m_stConnectionTestStatus, 1, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
|
||||
|
||||
|
|
|
@ -831,7 +831,7 @@
|
|||
<property name="resize">Resizable</property>
|
||||
<property name="show">1</property>
|
||||
<property name="size"></property>
|
||||
<property name="style"></property>
|
||||
<property name="style">wxST_ELLIPSIZE_MIDDLE</property>
|
||||
<property name="subclass">; ; forward_declare</property>
|
||||
<property name="toolbar_pane">0</property>
|
||||
<property name="tooltip"></property>
|
||||
|
|
|
@ -66,6 +66,9 @@ void SCH_DATABASE_PLUGIN::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolL
|
|||
ensureSettings( aLibraryPath );
|
||||
ensureConnection();
|
||||
|
||||
if( !m_conn )
|
||||
THROW_IO_ERROR( m_lastError );
|
||||
|
||||
bool powerSymbolsOnly = ( aProperties &&
|
||||
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) !=
|
||||
aProperties->end() );
|
||||
|
@ -112,6 +115,9 @@ LIB_SYMBOL* SCH_DATABASE_PLUGIN::LoadSymbol( const wxString& aLibraryPath,
|
|||
ensureSettings( aLibraryPath );
|
||||
ensureConnection();
|
||||
|
||||
if( !m_conn )
|
||||
THROW_IO_ERROR( m_lastError );
|
||||
|
||||
/*
|
||||
* Table names are tricky, in order to allow maximum flexibility to the user.
|
||||
* The slash character is used as a separator between a table name and symbol name, but symbol
|
||||
|
@ -215,8 +221,8 @@ bool SCH_DATABASE_PLUGIN::TestConnection( wxString* aErrorMsg )
|
|||
|
||||
connect();
|
||||
|
||||
if( aErrorMsg && m_conn && !m_conn->IsConnected() )
|
||||
*aErrorMsg = m_conn->GetLastError();
|
||||
if( aErrorMsg && ( !m_conn || !m_conn->IsConnected() ) )
|
||||
*aErrorMsg = m_lastError;
|
||||
|
||||
return m_conn && m_conn->IsConnected();
|
||||
}
|
||||
|
@ -272,8 +278,7 @@ void SCH_DATABASE_PLUGIN::ensureConnection()
|
|||
{
|
||||
wxString msg = wxString::Format(
|
||||
_( "Could not load database library: could not connect to database %s (%s)" ),
|
||||
m_settings->m_Source.dsn,
|
||||
m_conn->GetLastError() );
|
||||
m_settings->m_Source.dsn, m_lastError );
|
||||
|
||||
THROW_IO_ERROR( msg );
|
||||
}
|
||||
|
@ -302,7 +307,7 @@ void SCH_DATABASE_PLUGIN::connect()
|
|||
std::string basePath( wxFileName( m_settings->GetFilename() ).GetPath().ToUTF8() );
|
||||
|
||||
// Database drivers that use files operate on absolute paths, so provide a mechanism
|
||||
// for specifing on-disk databases that live next to the kicad_dbl file
|
||||
// for specifying on-disk databases that live next to the kicad_dbl file
|
||||
boost::replace_all( cs, "${CWD}", basePath );
|
||||
|
||||
m_conn = std::make_unique<DATABASE_CONNECTION>( cs, m_settings->m_Source.timeout );
|
||||
|
@ -310,6 +315,7 @@ void SCH_DATABASE_PLUGIN::connect()
|
|||
|
||||
if( !m_conn->IsConnected() )
|
||||
{
|
||||
m_lastError = m_conn->GetLastError();
|
||||
m_conn.reset();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -115,12 +115,14 @@ private:
|
|||
|
||||
std::unique_ptr<DATABASE_LIB_SETTINGS> m_settings;
|
||||
|
||||
/// Generally will be null if no valid connection is established
|
||||
std::unique_ptr<DATABASE_CONNECTION> m_conn;
|
||||
|
||||
std::set<wxString> m_customFields;
|
||||
|
||||
std::set<wxString> m_defaultShownFields;
|
||||
|
||||
wxString m_lastError;
|
||||
};
|
||||
|
||||
#endif //KICAD_SCH_DATABASE_PLUGIN_H
|
||||
|
|
Loading…
Reference in New Issue