mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 07:49:42 +01:00
* Keep retrying sql queries forever, as long as the returned db error indicates the db is just busy / locked.
This commit is contained in:
parent
25ef791afc
commit
9443992ff9
@ -59,8 +59,11 @@ TomahawkSqlQuery::exec()
|
||||
unsigned int retries = 0;
|
||||
while ( !QSqlQuery::exec() && ++retries < 10 )
|
||||
{
|
||||
tDebug() << "INFO: Retrying failed query:" << this->lastQuery() << this->lastError().text();
|
||||
TomahawkUtils::msleep( 25 );
|
||||
if ( isBusyError( lastError() ) )
|
||||
retries = 0;
|
||||
|
||||
tDebug() << "INFO: Retrying failed query:" << lastQuery() << lastError().text();
|
||||
TomahawkUtils::msleep( 10 );
|
||||
}
|
||||
|
||||
bool ret = ( retries < 10 );
|
||||
@ -87,8 +90,11 @@ TomahawkSqlQuery::commitTransaction()
|
||||
unsigned int retries = 0;
|
||||
while ( !m_db.commit() && ++retries < 10 )
|
||||
{
|
||||
tDebug() << "INFO: Retrying failed commit:" << this->lastQuery() << this->lastError().text();
|
||||
TomahawkUtils::msleep( 25 );
|
||||
if ( isBusyError( lastError() ) )
|
||||
retries = 0;
|
||||
|
||||
tDebug() << "INFO: Retrying failed commit:" << lastQuery() << lastError().text();
|
||||
TomahawkUtils::msleep( 10 );
|
||||
}
|
||||
|
||||
return ( retries < 10 );
|
||||
@ -98,10 +104,19 @@ TomahawkSqlQuery::commitTransaction()
|
||||
void
|
||||
TomahawkSqlQuery::showError()
|
||||
{
|
||||
tLog() << "\n" << "*** DATABASE ERROR ***" << "\n"
|
||||
<< this->lastQuery() << "\n"
|
||||
<< "boundValues:" << this->boundValues() << "\n"
|
||||
<< this->lastError().text() << "\n";
|
||||
tLog() << endl << "*** DATABASE ERROR ***" << endl
|
||||
<< lastQuery() << endl
|
||||
<< "boundValues:" << boundValues() << endl
|
||||
<< lastError().text() << endl;
|
||||
|
||||
Q_ASSERT( false );
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TomahawkSqlQuery::isBusyError( const QSqlError& error )
|
||||
{
|
||||
const QString text = error.text().toLower();
|
||||
|
||||
return ( text.contains( "locked" ) || text.contains( "busy" ) );
|
||||
}
|
||||
|
@ -38,6 +38,8 @@ public:
|
||||
bool commitTransaction();
|
||||
|
||||
private:
|
||||
bool isBusyError( const QSqlError& error );
|
||||
|
||||
void showError();
|
||||
|
||||
QSqlDatabase m_db;
|
||||
|
Loading…
x
Reference in New Issue
Block a user