1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-28 03:32:27 +01:00

* Auto re-prepare query on weird 'no query' error.

This commit is contained in:
Christian Muehlhaeuser 2012-06-26 04:03:03 +02:00
parent dbd137a561
commit 6fc4f2a89a
2 changed files with 21 additions and 5 deletions

View File

@ -51,6 +51,14 @@ TomahawkSqlQuery::escape( QString identifier )
}
bool
TomahawkSqlQuery::prepare( const QString& query )
{
m_query = query;
return QSqlQuery::prepare( query );
}
bool
TomahawkSqlQuery::exec( const QString& query )
{
@ -76,6 +84,12 @@ TomahawkSqlQuery::exec()
unsigned int retries = 0;
while ( !QSqlQuery::exec() && ++retries < 10 )
{
if ( lastError().text().toLower().contains( "no query" ) )
{
tDebug() << Q_FUNC_INFO << "Re-preparing query!";
prepare( m_query );
}
if ( isBusyError( lastError() ) )
retries = 0;
@ -104,7 +118,7 @@ TomahawkSqlQuery::commitTransaction()
#endif
if ( log )
tLog( LOGSQL ) << "TomahawkSqlQuery::commitTransaction running in thread " << QThread::currentThread();
unsigned int retries = 0;
while ( !m_db.commit() && ++retries < 10 )
{
@ -114,7 +128,7 @@ TomahawkSqlQuery::commitTransaction()
tDebug() << "INFO: Retrying failed commit:" << retries << lastError().text();
TomahawkUtils::msleep( 10 );
}
return ( retries < 10 );
}
@ -136,5 +150,5 @@ TomahawkSqlQuery::isBusyError( const QSqlError& error ) const
{
const QString text = error.text().trimmed().toLower();
return ( text.contains( "no query" ) || text.contains( "locked" ) || text.contains( "busy" ) || text.isEmpty() );
return ( text.contains( "locked" ) || text.contains( "busy" ) || text.isEmpty() );
}

View File

@ -35,17 +35,19 @@ public:
static QString escape( QString identifier );
bool prepare( const QString& query );
bool exec( const QString& query );
bool exec();
bool commitTransaction();
private:
bool isBusyError( const QSqlError& error ) const;
void showError();
QSqlDatabase m_db;
QString m_query;
};
#endif // TOMAHAWKSQLQUERY_H