mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02:00
* Auto re-prepare query on weird 'no query' error.
This commit is contained in:
@@ -51,6 +51,14 @@ TomahawkSqlQuery::escape( QString identifier )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
TomahawkSqlQuery::prepare( const QString& query )
|
||||||
|
{
|
||||||
|
m_query = query;
|
||||||
|
return QSqlQuery::prepare( query );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
TomahawkSqlQuery::exec( const QString& query )
|
TomahawkSqlQuery::exec( const QString& query )
|
||||||
{
|
{
|
||||||
@@ -76,6 +84,12 @@ TomahawkSqlQuery::exec()
|
|||||||
unsigned int retries = 0;
|
unsigned int retries = 0;
|
||||||
while ( !QSqlQuery::exec() && ++retries < 10 )
|
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() ) )
|
if ( isBusyError( lastError() ) )
|
||||||
retries = 0;
|
retries = 0;
|
||||||
|
|
||||||
@@ -104,7 +118,7 @@ TomahawkSqlQuery::commitTransaction()
|
|||||||
#endif
|
#endif
|
||||||
if ( log )
|
if ( log )
|
||||||
tLog( LOGSQL ) << "TomahawkSqlQuery::commitTransaction running in thread " << QThread::currentThread();
|
tLog( LOGSQL ) << "TomahawkSqlQuery::commitTransaction running in thread " << QThread::currentThread();
|
||||||
|
|
||||||
unsigned int retries = 0;
|
unsigned int retries = 0;
|
||||||
while ( !m_db.commit() && ++retries < 10 )
|
while ( !m_db.commit() && ++retries < 10 )
|
||||||
{
|
{
|
||||||
@@ -114,7 +128,7 @@ TomahawkSqlQuery::commitTransaction()
|
|||||||
tDebug() << "INFO: Retrying failed commit:" << retries << lastError().text();
|
tDebug() << "INFO: Retrying failed commit:" << retries << lastError().text();
|
||||||
TomahawkUtils::msleep( 10 );
|
TomahawkUtils::msleep( 10 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return ( retries < 10 );
|
return ( retries < 10 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,5 +150,5 @@ TomahawkSqlQuery::isBusyError( const QSqlError& error ) const
|
|||||||
{
|
{
|
||||||
const QString text = error.text().trimmed().toLower();
|
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() );
|
||||||
}
|
}
|
||||||
|
@@ -35,17 +35,19 @@ public:
|
|||||||
|
|
||||||
static QString escape( QString identifier );
|
static QString escape( QString identifier );
|
||||||
|
|
||||||
|
bool prepare( const QString& query );
|
||||||
bool exec( const QString& query );
|
bool exec( const QString& query );
|
||||||
bool exec();
|
bool exec();
|
||||||
|
|
||||||
bool commitTransaction();
|
bool commitTransaction();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isBusyError( const QSqlError& error ) const;
|
bool isBusyError( const QSqlError& error ) const;
|
||||||
|
|
||||||
void showError();
|
void showError();
|
||||||
|
|
||||||
QSqlDatabase m_db;
|
QSqlDatabase m_db;
|
||||||
|
QString m_query;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TOMAHAWKSQLQUERY_H
|
#endif // TOMAHAWKSQLQUERY_H
|
||||||
|
Reference in New Issue
Block a user