Show error dialog for failed SQL queries
This commit is contained in:
@@ -97,6 +97,7 @@ void SCollection::Init() {
|
||||
watcher_->set_backend(backend_);
|
||||
watcher_->set_task_manager(app_->task_manager());
|
||||
|
||||
QObject::connect(backend_, &CollectionBackend::Error, this, &SCollection::Error);
|
||||
QObject::connect(backend_, &CollectionBackend::DirectoryDiscovered, watcher_, &CollectionWatcher::AddDirectory);
|
||||
QObject::connect(backend_, &CollectionBackend::DirectoryDeleted, watcher_, &CollectionWatcher::RemoveDirectory);
|
||||
QObject::connect(watcher_, &CollectionWatcher::NewOrUpdatedSongs, backend_, &CollectionBackend::AddOrUpdateSongs);
|
||||
|
||||
@@ -79,6 +79,7 @@ class SCollection : public QObject {
|
||||
void ExitReceived();
|
||||
|
||||
signals:
|
||||
void Error(QString);
|
||||
void ExitFinished();
|
||||
|
||||
private:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -35,6 +35,7 @@
|
||||
#include <QSqlQuery>
|
||||
|
||||
#include "core/song.h"
|
||||
#include "core/sqlquery.h"
|
||||
#include "collectionquery.h"
|
||||
#include "directory.h"
|
||||
|
||||
@@ -131,6 +132,8 @@ class CollectionBackend : public CollectionBackendInterface {
|
||||
|
||||
void ExitAsync();
|
||||
|
||||
void ReportErrors(const CollectionQuery &query);
|
||||
|
||||
Database *db() const override { return db_; }
|
||||
|
||||
QString songs_table() const override { return songs_table_; }
|
||||
@@ -180,7 +183,7 @@ class CollectionBackend : public CollectionBackendInterface {
|
||||
void AddDirectory(const QString &path) override;
|
||||
void RemoveDirectory(const Directory &dir) override;
|
||||
|
||||
SongList ExecCollectionQuery(CollectionQuery *query);
|
||||
bool ExecCollectionQuery(CollectionQuery *query, SongList &songs);
|
||||
|
||||
void IncrementPlayCountAsync(const int id);
|
||||
void IncrementSkipCountAsync(const int id, const float progress);
|
||||
@@ -250,6 +253,8 @@ class CollectionBackend : public CollectionBackendInterface {
|
||||
|
||||
void ExitFinished();
|
||||
|
||||
void Error(QString);
|
||||
|
||||
private:
|
||||
struct CompilationInfo {
|
||||
CompilationInfo() : has_compilation_detected(0), has_not_compilation_detected(0) {}
|
||||
@@ -261,7 +266,7 @@ class CollectionBackend : public CollectionBackendInterface {
|
||||
int has_not_compilation_detected;
|
||||
};
|
||||
|
||||
void UpdateCompilations(QSqlQuery &find_song, QSqlQuery &update_song, SongList &deleted_songs, SongList &added_songs, const QUrl &url, const bool compilation_detected);
|
||||
bool UpdateCompilations(const QSqlDatabase &db, SongList &deleted_songs, SongList &added_songs, const QUrl &url, const bool compilation_detected);
|
||||
AlbumList GetAlbums(const QString &artist, const QString &album_artist, const bool compilation_required = false, const QueryOptions &opt = QueryOptions());
|
||||
AlbumList GetAlbums(const QString &artist, const bool compilation_required, const QueryOptions &opt = QueryOptions());
|
||||
SubdirectoryList SubdirsInDirectory(const int id, QSqlDatabase &db);
|
||||
|
||||
@@ -826,7 +826,10 @@ bool CollectionModel::HasCompilations(const QSqlDatabase &db, const CollectionQu
|
||||
q.AddCompilationRequirement(true);
|
||||
q.SetLimit(1);
|
||||
|
||||
if (!q.Exec()) return false;
|
||||
if (!q.Exec()) {
|
||||
backend_->ReportErrors(q);
|
||||
return false;
|
||||
}
|
||||
|
||||
return q.Next();
|
||||
|
||||
@@ -873,6 +876,9 @@ CollectionModel::QueryResult CollectionModel::RunQuery(CollectionItem *parent) {
|
||||
result.rows << SqlRow(q);
|
||||
}
|
||||
}
|
||||
else {
|
||||
backend_->ReportErrors(q);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -220,18 +220,7 @@ bool CollectionQuery::Exec() {
|
||||
addBindValue(value);
|
||||
}
|
||||
|
||||
const bool result = exec();
|
||||
|
||||
if (!result) {
|
||||
QSqlError last_error = lastError();
|
||||
if (last_error.isValid()) {
|
||||
qLog(Error) << "DB error: " << last_error;
|
||||
qLog(Error) << "Faulty query: " << lastQuery();
|
||||
qLog(Error) << "Bound values: " << boundValues();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return exec();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QMap>
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlQuery>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user