Comment(s) from r2281

This commit is contained in:
David Sansome 2010-11-23 23:10:53 +00:00
parent 83948e4973
commit 9a8d01e2bd
1 changed files with 27 additions and 25 deletions

View File

@ -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();
}