From 5fadd655f182fe0451a202ad75c51a53fc8f031c Mon Sep 17 00:00:00 2001 From: Marcos CARDINOT Date: Tue, 29 Jul 2014 21:59:33 +0100 Subject: [PATCH] CoverArtDAO - add method to save multi cover arts at once (from qlist) --- src/library/dao/coverartdao.cpp | 38 +++++++++++++++++++++++++++++++++ src/library/dao/coverartdao.h | 1 + 2 files changed, 39 insertions(+) diff --git a/src/library/dao/coverartdao.cpp b/src/library/dao/coverartdao.cpp index 7126a9c91fe..1adbbaf4d10 100644 --- a/src/library/dao/coverartdao.cpp +++ b/src/library/dao/coverartdao.cpp @@ -45,6 +45,44 @@ int CoverArtDAO::saveCoverArt(QString coverLocation, QString md5Hash) { return coverId; } +QList CoverArtDAO::saveCoverArt(QList > covers) { + if (covers.isEmpty()) { + return QList(); + } + + // it'll be used to avoid writing a new ID for + // rows which have the same md5 (not changed). + QString selectCoverId = QString("SELECT id FROM cover_art WHERE md5='%1'"); + + // preparing query to insert multi rows + QString sQuery; + sQuery = QString("INSERT OR REPLACE INTO cover_art ('id', 'location', 'md5') " + "SELECT (%1) AS 'id', '%2' AS 'location', '%3' AS 'md5' ") + .arg(selectCoverId.arg(covers.first().second)) + .arg(covers.first().first) + .arg(covers.first().second); + for (int i=1; i(); + } + + // getting the last inserted cover id's + QList coverIds; + for (int index=0; index saveCoverArt(QList > covers); struct CoverArtInfo { int trackId;