Add function for loading a single folder by id

This commit is contained in:
Luis Ángel San Martín 2024-01-07 09:18:16 +01:00
parent 15619ed96c
commit 9e05f8ea6e
2 changed files with 52 additions and 0 deletions

View File

@ -189,6 +189,57 @@ QString DBHelper::getFolderName(qulonglong libraryId, qulonglong id)
QSqlDatabase::removeDatabase(connectionName);
return name;
}
Folder DBHelper::getFolder(qulonglong libraryId, qulonglong id)
{
QString libraryPath = DBHelper::getLibraries().getPath(libraryId);
Folder folder;
QString connectionName = "";
{
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath + "/.yacreaderlibrary");
QSqlQuery selectQuery(db); // TODO check
selectQuery.prepare("SELECT * FROM folder WHERE id = :id");
selectQuery.bindValue(":id", id);
selectQuery.exec();
auto record = selectQuery.record();
int name = record.indexOf("name");
int path = record.indexOf("path");
int finished = record.indexOf("finished");
int completed = record.indexOf("completed");
int id = record.indexOf("id");
int parentId = record.indexOf("parentId");
int numChildren = record.indexOf("numChildren");
int firstChildHash = record.indexOf("firstChildHash");
int customImage = record.indexOf("customImage");
int type = record.indexOf("type");
int added = record.indexOf("added");
int updated = record.indexOf("updated");
if (selectQuery.next()) {
folder = Folder(selectQuery.value(id).toULongLong(), parentId, selectQuery.value(name).toString(), selectQuery.value(path).toString());
folder.finished = selectQuery.value(finished).toBool();
folder.completed = selectQuery.value(completed).toBool();
if (!selectQuery.value(numChildren).isNull() && selectQuery.value(numChildren).isValid()) {
folder.numChildren = selectQuery.value(numChildren).toInt();
}
folder.firstChildHash = selectQuery.value(firstChildHash).toString();
folder.customImage = selectQuery.value(customImage).toString();
folder.type = selectQuery.value(type).value<YACReader::FileType>();
folder.added = selectQuery.value(added).toLongLong();
folder.updated = selectQuery.value(updated).toLongLong();
}
connectionName = db.connectionName();
}
QSqlDatabase::removeDatabase(connectionName);
return folder;
}
QList<QString> DBHelper::getLibrariesNames()
{
auto names = getLibraries().getNames();

View File

@ -31,6 +31,7 @@ public:
static ComicDB getComicInfo(qulonglong libraryId, qulonglong id);
static QList<ComicDB> getSiblings(qulonglong libraryId, qulonglong parentId);
static QString getFolderName(qulonglong libraryId, qulonglong id);
static Folder getFolder(qulonglong libraryId, qulonglong id);
static QList<QString> getLibrariesNames();
static QString getLibraryName(int id);
static QList<ComicDB> getLabelComics(qulonglong libraryId, qulonglong labelId);