summaryrefslogtreecommitdiffstats
path: root/indexerwidget.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2017-02-25 06:46:51 +0100
committerArno <arno@disconnect.de>2017-02-25 06:46:51 +0100
commit25bcad4c8496431f1a5556803eaccea9dddc31e1 (patch)
tree62b220ecf3b7773f171fc78279f8e53e0ab40cf4 /indexerwidget.cpp
parent0e883223783a0e3ee5bc83f4ffeb4acc0beed1aa (diff)
downloadBeetPlayer-25bcad4c8496431f1a5556803eaccea9dddc31e1.tar.gz
BeetPlayer-25bcad4c8496431f1a5556803eaccea9dddc31e1.tar.bz2
BeetPlayer-25bcad4c8496431f1a5556803eaccea9dddc31e1.zip
Fix Indexer
Well, as it turns out, an artist is not married to an album, but to a song, and so is the genre. Adjust the database layout, indexer and view accordingly.
Diffstat (limited to 'indexerwidget.cpp')
-rw-r--r--indexerwidget.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/indexerwidget.cpp b/indexerwidget.cpp
index 84f2598..e1643fa 100644
--- a/indexerwidget.cpp
+++ b/indexerwidget.cpp
@@ -94,11 +94,11 @@ BeetReader::BeetReader() : mCanceled(false){
mCurGenresQ = new QSqlQuery(mDb);
mCurGenresQ->prepare("SELECT currval('genres_igenre_id__seq')");
mInsertAlbumQ = new QSqlQuery(mDb);
- mInsertAlbumQ->prepare("INSERT INTO albums(iartists_id, igenres_id, talbum_name, siyear) VALUES(:aid, :genid, :name, :year)");
+ mInsertAlbumQ->prepare("INSERT INTO albums(talbum_name, siyear) VALUES(:name, :year)");
mCurAlbumQ = new QSqlQuery(mDb);
mCurAlbumQ->prepare("SELECT currval('albums_ialbums_id__seq')");
mInsertSongQ = new QSqlQuery(mDb);
- mInsertSongQ->prepare("INSERT INTO songs (ialbums_id, sipos, ttitle, tfullpath) VALUES(:aid, :pos, :title, :tfp)");
+ mInsertSongQ->prepare("INSERT INTO songs (ialbums_id, sipos, ttitle, iartists_id, igenres_id, tfullpath) VALUES(:aid, :pos, :title, :iartistid, :igenid, :tfp)");
}
void BeetReader::run(){
@@ -136,8 +136,8 @@ void BeetReader::run(){
//write to database
int artistId = doArtist(artist);
int genreId = doGenre(genre);
- int albumId = doAlbum(album, genreId, artistId, year, QString(s).toUtf8());
- doSong(title, track, albumId, s);
+ int albumId = doAlbum(album, year);
+ doSong(title, track, albumId, genreId, artistId, s);
if(ctr % 100 == 0){
QString msg = QString(tr("Processed %1 files of %2")).arg(QString::number(ctr)).arg(QString::number(totalCount));
@@ -176,6 +176,8 @@ void BeetReader::clearAll(){
mArtistH.clear();
mAlbumH.clear();
mGenreH.clear();
+ QSqlQuery q5("INSERT INTO genres VALUES(-1, 'none')", mDb);
+ q5.exec();
emit cleared();
}
@@ -214,16 +216,13 @@ int BeetReader::doGenre(QString name){
return retval;
}
-int BeetReader::doAlbum(QString name, int genre, int artist, int year, QString fullPath){
- QFileInfo fi(fullPath);
- QString key = fi.absolutePath();
+int BeetReader::doAlbum(QString name, int year){
+ QString key = name;
if(mAlbumH.contains(key)){
return mAlbumH.value(key);
}
mDb.transaction();
mInsertAlbumQ->bindValue(":name", name);
- mInsertAlbumQ->bindValue(":aid", artist);
- mInsertAlbumQ->bindValue(":genid", genre);
mInsertAlbumQ->bindValue(":year", year);
mInsertAlbumQ->exec();
int retval = -1;
@@ -236,11 +235,13 @@ int BeetReader::doAlbum(QString name, int genre, int artist, int year, QString f
return retval;
}
-void BeetReader::doSong(QString title, int pos, int album, QString fullpath){
+void BeetReader::doSong(QString title, int pos, int album, int genre, int artist, QString fullpath){
mDb.transaction();
mInsertSongQ->bindValue(":title", title);
mInsertSongQ->bindValue(":pos", pos);
mInsertSongQ->bindValue(":aid", album);
+ mInsertSongQ->bindValue(":iartistid", artist);
+ mInsertSongQ->bindValue(":igenid", genre);
mInsertSongQ->bindValue(":tfp", fullpath);
mInsertSongQ->exec();
mDb.commit();