@@ -22,16 +22,11 @@ CAccountManager::CAccountManager ( const SString& strDbPathFilename )
22
22
m_bChangedSinceSaved = false ;
23
23
m_iAccounts = 1 ;
24
24
m_pDatabaseManager = g_pGame->GetDatabaseManager ();
25
+ m_strDbPathFilename = strDbPathFilename;
26
+ m_hDbConnection = INVALID_DB_HANDLE;
25
27
26
28
// Load internal.db
27
- SString strOptions;
28
- #ifdef WITH_ACCOUNT_QUERY_LOGGING
29
- g_pGame->GetDatabaseManager ()->SetLogLevel ( EJobLogLevel::ALL, g_pGame->GetConfig ()->GetDbLogFilename () );
30
- SetOption < CDbOptionsMap > ( strOptions, " log" , 1 );
31
- SetOption < CDbOptionsMap > ( strOptions, " tag" , " accounts" );
32
- #endif
33
- SetOption < CDbOptionsMap > ( strOptions, " queue" , DB_SQLITE_QUEUE_NAME_INTERNAL );
34
- m_hDbConnection = m_pDatabaseManager->Connect ( " sqlite" , PathConform ( strDbPathFilename ), " " , " " , strOptions );
29
+ ReconnectToDatabase ();
35
30
36
31
// Check if new installation
37
32
CRegistryResult result;
@@ -119,6 +114,25 @@ CAccountManager::~CAccountManager ( void )
119
114
}
120
115
121
116
117
+ void CAccountManager::ReconnectToDatabase (void )
118
+ {
119
+ if (m_hDbConnection != INVALID_DB_HANDLE)
120
+ {
121
+ m_pDatabaseManager->Disconnect (m_hDbConnection);
122
+ }
123
+
124
+ // Load internal.db
125
+ SString strOptions;
126
+ #ifdef WITH_ACCOUNT_QUERY_LOGGING
127
+ g_pGame->GetDatabaseManager ()->SetLogLevel ( EJobLogLevel::ALL, g_pGame->GetConfig ()->GetDbLogFilename () );
128
+ SetOption < CDbOptionsMap > ( strOptions, " log" , 1 );
129
+ SetOption < CDbOptionsMap > ( strOptions, " tag" , " accounts" );
130
+ #endif
131
+ SetOption < CDbOptionsMap > ( strOptions, " queue" , DB_SQLITE_QUEUE_NAME_INTERNAL );
132
+ m_hDbConnection = m_pDatabaseManager->Connect ( " sqlite" , PathConform ( m_strDbPathFilename ), " " , " " , strOptions );
133
+ }
134
+
135
+
122
136
void CAccountManager::DoPulse ( void )
123
137
{
124
138
// Save it only once in a while whenever something has changed
@@ -926,8 +940,16 @@ void CAccountManager::DbCallback ( CDbJobData* pJobData )
926
940
{
927
941
if ( m_pDatabaseManager->QueryPoll ( pJobData, 0 ) )
928
942
{
929
- if ( pJobData->result .status == EJobResult::FAIL )
943
+ if ( pJobData->result .status == EJobResult::FAIL )
944
+ {
930
945
CLogger::LogPrintf ( " ERROR: While updating account with '%s': %s.\n " , *pJobData->command .strData , *pJobData->result .strReason );
946
+ if (pJobData->result .strReason .ContainsI (" missing database" ))
947
+ {
948
+ // Try reconnection
949
+ CLogger::LogPrintf (" INFO: Reconnecting to accounts database\n " );
950
+ ReconnectToDatabase ();
951
+ }
952
+ }
931
953
}
932
954
else
933
955
{
0 commit comments