From 3ecbab3c6359d6a72740e0a00cc1a6bf02eb71de Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 28 Nov 2012 04:59:23 +0100 Subject: [PATCH] * Extra safety for QJson 0.8.0. --- .../DatabaseCommand_LoadPlaylistEntries.cpp | 73 ++++++++++--------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/src/libtomahawk/database/DatabaseCommand_LoadPlaylistEntries.cpp b/src/libtomahawk/database/DatabaseCommand_LoadPlaylistEntries.cpp index 5a17641e7..5b074878b 100644 --- a/src/libtomahawk/database/DatabaseCommand_LoadPlaylistEntries.cpp +++ b/src/libtomahawk/database/DatabaseCommand_LoadPlaylistEntries.cpp @@ -54,41 +54,45 @@ DatabaseCommand_LoadPlaylistEntries::generateEntries( DatabaseImpl* dbi ) if ( query_entries.next() ) { - // entries should be a list of strings: - QVariant v = parser.parse( query_entries.value( 0 ).toByteArray(), &ok ); - Q_ASSERT( ok && v.type() == QVariant::List ); //TODO - m_guids = v.toStringList(); - QString inclause = QString( "('%1')" ).arg( m_guids.join( "', '" ) ); - - TomahawkSqlQuery query = dbi->newquery(); - QString sql = QString( "SELECT guid, trackname, artistname, albumname, annotation, " - "duration, addedon, addedby, result_hint " - "FROM playlist_item " - "WHERE guid IN %1" ).arg( inclause ); - - query.exec( sql ); - while ( query.next() ) + if ( !query_entries.value( 0 ).isNull() ) { - plentry_ptr e( new PlaylistEntry ); - e->setGuid( query.value( 0 ).toString() ); - e->setAnnotation( query.value( 4 ).toString() ); - e->setDuration( query.value( 5 ).toUInt() ); - e->setLastmodified( 0 ); // TODO e->lastmodified = query.value( 6 ).toInt(); - const QString resultHint = query.value( 8 ).toString(); - e->setResultHint( resultHint ); + // entries should be a list of strings: + QVariant v = parser.parse( query_entries.value( 0 ).toByteArray(), &ok ); + Q_ASSERT( ok && v.type() == QVariant::List ); //TODO - Tomahawk::query_ptr q = Tomahawk::Query::get( query.value( 2 ).toString(), query.value( 1 ).toString(), query.value( 3 ).toString() ); - if ( q.isNull() ) - continue; + m_guids = v.toStringList(); + QString inclause = QString( "('%1')" ).arg( m_guids.join( "', '" ) ); - q->setResultHint( resultHint ); - if ( resultHint.startsWith( "http" ) ) - q->setSaveHTTPResultHint( true ); + TomahawkSqlQuery query = dbi->newquery(); + QString sql = QString( "SELECT guid, trackname, artistname, albumname, annotation, " + "duration, addedon, addedby, result_hint " + "FROM playlist_item " + "WHERE guid IN %1" ).arg( inclause ); - q->setProperty( "annotation", e->annotation() ); - e->setQuery( q ); + query.exec( sql ); + while ( query.next() ) + { + plentry_ptr e( new PlaylistEntry ); + e->setGuid( query.value( 0 ).toString() ); + e->setAnnotation( query.value( 4 ).toString() ); + e->setDuration( query.value( 5 ).toUInt() ); + e->setLastmodified( 0 ); // TODO e->lastmodified = query.value( 6 ).toInt(); + const QString resultHint = query.value( 8 ).toString(); + e->setResultHint( resultHint ); - m_entrymap.insert( e->guid(), e ); + Tomahawk::query_ptr q = Tomahawk::Query::get( query.value( 2 ).toString(), query.value( 1 ).toString(), query.value( 3 ).toString() ); + if ( q.isNull() ) + continue; + + q->setResultHint( resultHint ); + if ( resultHint.startsWith( "http" ) ) + q->setSaveHTTPResultHint( true ); + + q->setProperty( "annotation", e->annotation() ); + e->setQuery( q ); + + m_entrymap.insert( e->guid(), e ); + } } prevrev = query_entries.value( 4 ).toString(); @@ -116,9 +120,12 @@ DatabaseCommand_LoadPlaylistEntries::generateEntries( DatabaseImpl* dbi ) Q_ASSERT( false ); } - QVariant v = parser.parse( query_entries_old.value( 0 ).toByteArray(), &ok ); - Q_ASSERT( ok && v.type() == QVariant::List ); //TODO - m_oldentries = v.toStringList(); + if ( !query_entries_old.value( 0 ).isNull() ) + { + QVariant v = parser.parse( query_entries_old.value( 0 ).toByteArray(), &ok ); + Q_ASSERT( ok && v.type() == QVariant::List ); //TODO + m_oldentries = v.toStringList(); + } m_islatest = query_entries_old.value( 1 ).toBool(); }