1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 21:57:41 +02: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 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;
@@ -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() );
} }

View File

@@ -35,6 +35,7 @@ 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();
@@ -46,6 +47,7 @@ private:
void showError(); void showError();
QSqlDatabase m_db; QSqlDatabase m_db;
QString m_query;
}; };
#endif // TOMAHAWKSQLQUERY_H #endif // TOMAHAWKSQLQUERY_H