| 1672 | } |
| 1673 | |
| 1674 | QList<ComicDB> DBHelper::getSortedComicsFromParent(qulonglong parentId, QSqlDatabase &db) |
| 1675 | { |
| 1676 | QList<ComicDB> list; |
| 1677 | |
| 1678 | QSqlQuery selectQuery(db); |
| 1679 | |
| 1680 | selectQuery.setForwardOnly(true); |
| 1681 | selectQuery.prepare("select * from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId"); |
| 1682 | selectQuery.bindValue(":parentId", parentId); |
| 1683 | selectQuery.exec(); |
| 1684 | |
| 1685 | QSqlRecord record = selectQuery.record(); |
| 1686 | |
| 1687 | int id = record.indexOf("id"); |
| 1688 | // int parentIdIndex = record.indexOf("parentId"); |
| 1689 | int fileName = record.indexOf("fileName"); |
| 1690 | int path = record.indexOf("path"); |
| 1691 | |
| 1692 | ComicDB currentItem; |
| 1693 | while (selectQuery.next()) { |
| 1694 | currentItem.id = selectQuery.value(id).toULongLong(); |
| 1695 | currentItem.parentId = parentId; // selectQuery.value(parentId).toULongLong(); |
| 1696 | currentItem.name = selectQuery.value(fileName).toString(); |
| 1697 | currentItem.path = selectQuery.value(path).toString(); |
| 1698 | |
| 1699 | currentItem.info = getComicInfoFromQuery(selectQuery, "comicInfoId"); |
| 1700 | |
| 1701 | list.append(currentItem); |
| 1702 | } |
| 1703 | |
| 1704 | std::sort(list.begin(), list.end(), [](const ComicDB &c1, const ComicDB &c2) { |
| 1705 | if (c1.info.number.isNull() && c2.info.number.isNull()) { |
| 1706 | return naturalSortLessThanCI(c1.name, c2.name); |
| 1707 | } else { |
| 1708 | if (c1.info.number.isNull() == false && c2.info.number.isNull() == false) { |
| 1709 | return naturalSortLessThanCI(c1.info.number.toString(), c2.info.number.toString()); |
| 1710 | } else { |
| 1711 | return c2.info.number.isNull(); |
| 1712 | } |
| 1713 | } |
| 1714 | }); |
| 1715 | |
| 1716 | // selectQuery.finish(); |
| 1717 | return list; |
| 1718 | } |
| 1719 | QList<LibraryItem *> DBHelper::getComicsFromParent(qulonglong parentId, QSqlDatabase &db, bool sort) |
| 1720 | { |
| 1721 | QList<LibraryItem *> list; |
nothing calls this directly
no test coverage detected