diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index f46b589f..c781d01e 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -58,6 +58,38 @@ QList DBHelper::getFolderComicsFromLibrary(qulonglong libraryId, QSqlDatabase::removeDatabase(libraryPath); return list; } + +quint32 DBHelper::getNumChildrenFromFolder(qulonglong libraryId, qulonglong folderId) +{ + QString libraryPath = DBHelper::getLibraries().getPath(libraryId); + QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary"); + + quint32 result = 0; + + { + QSqlQuery selectQuery(db); + selectQuery.prepare("SELECT count(*) FROM folder WHERE parentId = :parentId and id <> 1"); + selectQuery.bindValue(":parentId", folderId); + selectQuery.exec(); + + result += selectQuery.record().value(0).toULongLong(); + } + + { + QSqlQuery selectQuery(db); + selectQuery.prepare("SELECT count(*) FROM comic c WHERE c.parentId = :parentId"); + selectQuery.bindValue(":parentId", folderId); + selectQuery.exec(); + + result += selectQuery.record().value(0).toULongLong(); + } + + db.close(); + QSqlDatabase::removeDatabase(libraryPath); + + return result; +} + qulonglong DBHelper::getParentFromComicFolderId(qulonglong libraryId, qulonglong id) { QString libraryPath = DBHelper::getLibraries().getPath(libraryId); diff --git a/YACReaderLibrary/db_helper.h b/YACReaderLibrary/db_helper.h index 5eb2eae3..19611dc7 100644 --- a/YACReaderLibrary/db_helper.h +++ b/YACReaderLibrary/db_helper.h @@ -23,6 +23,7 @@ public: static QList getFolderSubfoldersFromLibrary(qulonglong libraryId, qulonglong folderId); static QList getFolderComicsFromLibrary(qulonglong libraryId, qulonglong folderId); static QList getFolderComicsFromLibrary(qulonglong libraryId, qulonglong folderId, bool sort); + static quint32 getNumChildrenFromFolder(qulonglong libraryId, qulonglong folderId); static qulonglong getParentFromComicFolderId(qulonglong libraryId, qulonglong id); static ComicDB getComicInfo(qulonglong libraryId, qulonglong id); static QList getSiblings(qulonglong libraryId, qulonglong parentId);