DbLib: Retry connection if first attempt fails

This commit is contained in:
Jon Evans 2022-08-30 20:58:49 -04:00
parent 5679b9dbdc
commit 1da0572977
1 changed files with 27 additions and 10 deletions

View File

@ -162,26 +162,41 @@ bool SCH_DATABASE_PLUGIN::CheckHeader( const wxString& aFileName )
void SCH_DATABASE_PLUGIN::ensureSettings( const wxString& aSettingsPath ) void SCH_DATABASE_PLUGIN::ensureSettings( const wxString& aSettingsPath )
{ {
auto tryLoad =
[&]()
{
if( !m_settings->LoadFromFile() )
{
wxString msg = wxString::Format(
_( "Could not load database library: settings file %s missing or invalid" ),
aSettingsPath );
THROW_IO_ERROR( msg );
}
};
if( !m_settings && !aSettingsPath.IsEmpty() ) if( !m_settings && !aSettingsPath.IsEmpty() )
{ {
std::string path( aSettingsPath.ToUTF8() ); std::string path( aSettingsPath.ToUTF8() );
m_settings = std::make_unique<DATABASE_LIB_SETTINGS>( path ); m_settings = std::make_unique<DATABASE_LIB_SETTINGS>( path );
m_settings->SetReadOnly( true ); m_settings->SetReadOnly( true );
if( !m_settings->LoadFromFile() ) tryLoad();
{
wxString msg = wxString::Format(
_( "Could not load database library: settings file %s missing or invalid" ),
aSettingsPath );
THROW_IO_ERROR( msg );
}
} }
else if( !m_settings ) else if( !m_conn && m_settings )
{
// If we have valid settings but no connection yet; reload settings in case user is editing
tryLoad();
}
else if( m_conn && m_settings && !aSettingsPath.IsEmpty() )
{ {
wxASSERT_MSG( aSettingsPath == m_settings->GetFilename(), wxASSERT_MSG( aSettingsPath == m_settings->GetFilename(),
"Path changed for database library without re-initializing plugin!" ); "Path changed for database library without re-initializing plugin!" );
} }
else if( !m_settings )
{
wxLogTrace( traceDatabase, wxT( "ensureSettings: no settings but no valid path!" ) );
}
} }
@ -217,6 +232,8 @@ void SCH_DATABASE_PLUGIN::ensureConnection()
m_settings->m_Source.dsn, m_settings->m_Source.dsn,
m_conn->GetLastError() ); m_conn->GetLastError() );
m_conn.reset();
THROW_IO_ERROR( msg ); THROW_IO_ERROR( msg );
} }
} }