From 9a8d01e2bd3aad8b1f03f2f00da8686e32c9e914 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Tue, 23 Nov 2010 23:10:53 +0000 Subject: [PATCH] Comment(s) from r2281 --- src/radio/icecastbackend.cpp | 52 +++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/radio/icecastbackend.cpp b/src/radio/icecastbackend.cpp index fa5ddb6fd..5872d80b0 100644 --- a/src/radio/icecastbackend.cpp +++ b/src/radio/icecastbackend.cpp @@ -138,35 +138,37 @@ bool IcecastBackend::IsEmpty() { } void IcecastBackend::ClearAndAddStations(const StationList& stations) { - QMutexLocker l(db_->Mutex()); - QSqlDatabase db = db_->Connect(); - ScopedTransaction t(&db); + { + QMutexLocker l(db_->Mutex()); + QSqlDatabase db = db_->Connect(); + ScopedTransaction t(&db); - // Remove all existing items - QSqlQuery q(QString("DELETE FROM %1").arg(kTableName), db); - q.exec(); - if (db_->CheckErrors(q.lastError())) return; - - q = QSqlQuery(QString("INSERT INTO %1 (name, url, mime_type, bitrate," - " channels, samplerate, genre)" - " VALUES (:name, :url, :mime_type, :bitrate," - " :channels, :samplerate, :genre)") - .arg(kTableName), db); - - // Add these ones - foreach (const Station& station, stations) { - q.bindValue(":name", station.name); - q.bindValue(":url", station.url); - q.bindValue(":mime_type", station.mime_type); - q.bindValue(":bitrate", station.bitrate); - q.bindValue(":channels", station.channels); - q.bindValue(":samplerate", station.samplerate); - q.bindValue(":genre", station.genre); + // Remove all existing items + QSqlQuery q(QString("DELETE FROM %1").arg(kTableName), db); q.exec(); if (db_->CheckErrors(q.lastError())) return; - } - t.Commit(); + q = QSqlQuery(QString("INSERT INTO %1 (name, url, mime_type, bitrate," + " channels, samplerate, genre)" + " VALUES (:name, :url, :mime_type, :bitrate," + " :channels, :samplerate, :genre)") + .arg(kTableName), db); + + // Add these ones + foreach (const Station& station, stations) { + q.bindValue(":name", station.name); + q.bindValue(":url", station.url); + q.bindValue(":mime_type", station.mime_type); + q.bindValue(":bitrate", station.bitrate); + q.bindValue(":channels", station.channels); + q.bindValue(":samplerate", station.samplerate); + q.bindValue(":genre", station.genre); + q.exec(); + if (db_->CheckErrors(q.lastError())) return; + } + + t.Commit(); + } emit DatabaseReset(); }