Make sure QSqlQuery::exec() was successful

This commit is contained in:
Jonas Kvinge 2019-11-25 22:43:09 +01:00
parent 3bb0ee916d
commit a4ebd91e8d
1 changed files with 15 additions and 14 deletions

View File

@ -787,10 +787,9 @@ Song CollectionBackend::GetSongByUrl(const QUrl &url, const qint64 beginning) {
q.bindValue(":url3", url.toString(QUrl::FullyEncoded)); q.bindValue(":url3", url.toString(QUrl::FullyEncoded));
q.bindValue(":url4", url.toEncoded()); q.bindValue(":url4", url.toEncoded());
q.bindValue(":beginning", beginning); q.bindValue(":beginning", beginning);
q.exec();
Song song(source_); Song song(source_);
if (q.next()) { if (q.exec() && q.next()) {
song.InitFromQuery(q, true); song.InitFromQuery(q, true);
} }
@ -810,14 +809,15 @@ SongList CollectionBackend::GetSongsByUrl(const QUrl &url) {
q.bindValue(":url2", url.toString()); q.bindValue(":url2", url.toString());
q.bindValue(":url3", url.toString(QUrl::FullyEncoded)); q.bindValue(":url3", url.toString(QUrl::FullyEncoded));
q.bindValue(":url4", url.toEncoded()); q.bindValue(":url4", url.toEncoded());
q.exec();
SongList songs; SongList songs;
if (q.exec()) {
while (q.next()) { while (q.next()) {
Song song(source_); Song song(source_);
song.InitFromQuery(q, true); song.InitFromQuery(q, true);
songs << song; songs << song;
} }
}
return songs; return songs;
@ -977,8 +977,8 @@ void CollectionBackend::UpdateCompilations(QSqlQuery &find_song, QSqlQuery &upda
find_song.bindValue(":url2", url.toString()); find_song.bindValue(":url2", url.toString());
find_song.bindValue(":url3", url.toString(QUrl::FullyEncoded)); find_song.bindValue(":url3", url.toString(QUrl::FullyEncoded));
find_song.bindValue(":url4", url.toEncoded()); find_song.bindValue(":url4", url.toEncoded());
find_song.exec();
if (find_song.exec()) {
while (find_song.next()) { while (find_song.next()) {
Song song(source_); Song song(source_);
song.InitFromQuery(find_song, true); song.InitFromQuery(find_song, true);
@ -986,6 +986,7 @@ void CollectionBackend::UpdateCompilations(QSqlQuery &find_song, QSqlQuery &upda
song.set_compilation_detected(compilation_detected); song.set_compilation_detected(compilation_detected);
added_songs << song; added_songs << song;
} }
}
// Update the song // Update the song
update_song.bindValue(":compilation_detected", int(compilation_detected)); update_song.bindValue(":compilation_detected", int(compilation_detected));