diff --git a/data/schema/device-schema.sql b/data/schema/device-schema.sql index 33b9c6b3a..2df96deb6 100644 --- a/data/schema/device-schema.sql +++ b/data/schema/device-schema.sql @@ -55,7 +55,10 @@ CREATE TABLE device_%deviceid_songs ( unavailable INTEGER DEFAULT 0, effective_albumartist TEXT, - etag TEXT + etag TEXT, + + performer TEXT, + grouping TEXT ); CREATE INDEX idx_device_%deviceid_songs_album ON device_%deviceid_songs (album); @@ -63,7 +66,7 @@ CREATE INDEX idx_device_%deviceid_songs_album ON device_%deviceid_songs (album); CREATE INDEX idx_device_%deviceid_songs_comp_artist ON device_%deviceid_songs (effective_compilation, artist); CREATE VIRTUAL TABLE device_%deviceid_fts USING fts3( - ftstitle, ftsalbum, ftsartist, ftsalbumartist, ftscomposer, ftsgenre, ftscomment, + ftstitle, ftsalbum, ftsartist, ftsalbumartist, ftscomposer, ftsperformer, ftsgrouping, ftsgenre, ftscomment, tokenize=unicode ); diff --git a/src/core/database.cpp b/src/core/database.cpp index 15e936f8e..39adf862b 100644 --- a/src/core/database.cpp +++ b/src/core/database.cpp @@ -500,8 +500,8 @@ void Database::UpdateDatabaseSchema(int version, QSqlDatabase &db) { } } qLog(Debug) << "Applying database schema update" << version - << "from" << filename; - ExecSchemaCommandsFromFile(db, filename, version - 1, &t); + << "from" << filename; + ExecSchemaCommandsFromFile(db, filename, version - 1, true); t.Commit(); } else { qLog(Debug) << "Applying database schema update" << version @@ -533,22 +533,25 @@ void Database::UrlEncodeFilenameColumn(const QString& table, QSqlDatabase& db) { } void Database::ExecSchemaCommandsFromFile(QSqlDatabase& db, - QString const& filename, + const QString& filename, int schema_version, - ScopedTransaction const* outerTransaction) { + bool in_transaction) { // Open and read the database schema QFile schema_file(filename); if (!schema_file.open(QIODevice::ReadOnly)) qFatal("Couldn't open schema file %s", filename.toUtf8().constData()); - ExecSchemaCommands(db, QString::fromUtf8(schema_file.readAll()), schema_version, outerTransaction); + ExecSchemaCommands(db, + QString::fromUtf8(schema_file.readAll()), + schema_version, + in_transaction); } void Database::ExecSchemaCommands(QSqlDatabase& db, - QString const& schema, + const QString& schema, int schema_version, - ScopedTransaction const* outerTransaction) { + bool in_transaction) { // Run each command - QStringList const schemaCommands(schema.split(";\n\n")); + const QStringList commands(schema.split(";\n\n")); // We don't want this list to reflect possible DB schema changes // so we initialize it before executing any statements. @@ -556,26 +559,26 @@ void Database::ExecSchemaCommands(QSqlDatabase& db, // be queried before beginning an inner transaction! Otherwise // DROP TABLE commands on song tables may fail due to database // locks. - QStringList const songTables(SongsTables(db, schema_version)); + const QStringList song_tables(SongsTables(db, schema_version)); - if (0 == outerTransaction) { - ScopedTransaction innerTransaction(&db); - ExecSongTablesCommands(db, songTables, schemaCommands); - innerTransaction.Commit(); + if (!in_transaction) { + ScopedTransaction inner_transaction(&db); + ExecSongTablesCommands(db, song_tables, commands); + inner_transaction.Commit(); } else { - ExecSongTablesCommands(db, songTables, schemaCommands); + ExecSongTablesCommands(db, song_tables, commands); } } void Database::ExecSongTablesCommands(QSqlDatabase& db, - QStringList const& songTables, - QStringList const& commands) { - foreach (QString const& command, commands) { + const QStringList& song_tables, + const QStringList& commands) { + foreach (const QString& command, commands) { // There are now lots of "songs" tables that need to have the same schema: // songs, magnatune_songs, and device_*_songs. We allow a magic value // in the schema files to update all songs tables at once. if (command.contains(kMagicAllSongsTables)) { - foreach (QString const& table, songTables) { + foreach (const QString& table, song_tables) { qLog(Info) << "Updating" << table << "for" << kMagicAllSongsTables; QString new_command(command); new_command.replace(kMagicAllSongsTables, table); diff --git a/src/core/database.h b/src/core/database.h index cc409cfe1..d865c1ad9 100644 --- a/src/core/database.h +++ b/src/core/database.h @@ -38,7 +38,6 @@ struct sqlite3_tokenizer_module; } class Application; -class ScopedTransaction; class Database : public QObject { Q_OBJECT @@ -56,7 +55,10 @@ class Database : public QObject { QMutex* Mutex() { return &mutex_; } void RecreateAttachedDb(const QString& database_name); - void ExecSchemaCommands(QSqlDatabase &db, QString const& schema, int schema_version, ScopedTransaction const* outerTransaction = 0); + void ExecSchemaCommands(QSqlDatabase& db, + const QString& schema, + int schema_version, + bool in_transaction = false); int startup_schema_version() const { return startup_schema_version_; } int current_schema_version() const { return kSchemaVersion; } @@ -70,8 +72,13 @@ class Database : public QObject { private: void UpdateMainSchema(QSqlDatabase* db); - void ExecSchemaCommandsFromFile(QSqlDatabase &db, QString const& filename, int schema_version, ScopedTransaction const* outerTransaction = 0); - void ExecSongTablesCommands(QSqlDatabase &db, QStringList const& songTables, QStringList const& commands); + void ExecSchemaCommandsFromFile(QSqlDatabase& db, + const QString& filename, + int schema_version, + bool in_transaction = false); + void ExecSongTablesCommands(QSqlDatabase& db, + const QStringList& song_tables, + const QStringList& commands); void UpdateDatabaseSchema(int version, QSqlDatabase& db); void UrlEncodeFilenameColumn(const QString& table, QSqlDatabase& db); diff --git a/src/devices/devicedatabasebackend.cpp b/src/devices/devicedatabasebackend.cpp index a7ace7425..7c83978e8 100644 --- a/src/devices/devicedatabasebackend.cpp +++ b/src/devices/devicedatabasebackend.cpp @@ -90,7 +90,7 @@ int DeviceDatabaseBackend::AddDevice(const Device& device) { QString schema = QString::fromUtf8(schema_file.readAll()); schema.replace("%deviceid", QString::number(id)); - db_->ExecSchemaCommands(db, schema, 0, &t); + db_->ExecSchemaCommands(db, schema, 0, true); t.Commit(); return id; diff --git a/src/playlist/playlist.h b/src/playlist/playlist.h index 16e9de037..4a05e29ee 100644 --- a/src/playlist/playlist.h +++ b/src/playlist/playlist.h @@ -90,8 +90,6 @@ class Playlist : public QAbstractListModel { Column_Album, Column_AlbumArtist, Column_Composer, - Column_Performer, - Column_Grouping, Column_Length, Column_Track, Column_Disc, @@ -119,6 +117,9 @@ class Playlist : public QAbstractListModel { Column_Source, Column_Mood, + Column_Performer, + Column_Grouping, + ColumnCount }; diff --git a/src/playlist/playlistview.cpp b/src/playlist/playlistview.cpp index 8281f8fce..734747200 100644 --- a/src/playlist/playlistview.cpp +++ b/src/playlist/playlistview.cpp @@ -46,7 +46,7 @@ # include "moodbar/moodbaritemdelegate.h" #endif -const int PlaylistView::kStateVersion = 5; +const int PlaylistView::kStateVersion = 6; const int PlaylistView::kGlowIntensitySteps = 24; const int PlaylistView::kAutoscrollGraceTimeout = 30; // seconds const int PlaylistView::kDropIndicatorWidth = 2; @@ -324,6 +324,10 @@ void PlaylistView::LoadGeometry() { if (state_version < 5) { header_->HideSection(Playlist::Column_Mood); } + if (state_version < 6) { + header_->HideSection(Playlist::Column_Performer); + header_->HideSection(Playlist::Column_Grouping); + } // Make sure at least one column is visible bool all_hidden = true;