| 306 | } |
| 307 | |
| 308 | QList<ComicDB> DBHelper::getFavorites(qulonglong libraryId) |
| 309 | { |
| 310 | QString libraryPath = DBHelper::getLibraries().getPath(libraryId); |
| 311 | QList<ComicDB> list; |
| 312 | |
| 313 | const int FAV_ID = 1; |
| 314 | QString connectionName = ""; |
| 315 | |
| 316 | { |
| 317 | QSqlDatabase db = DataBaseManagement::loadDatabase(LibraryPaths::libraryDataPath(libraryPath)); |
| 318 | QSqlQuery selectQuery(db); |
| 319 | selectQuery.prepare("SELECT c.id,c.fileName,ci.title,ci.currentPage,ci.numPages,ci.hash,ci.read,ci.coverSizeRatio,ci.number " |
| 320 | "FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) " |
| 321 | "INNER JOIN comic_default_reading_list cdrl ON (c.id == cdrl.comic_id) " |
| 322 | "WHERE cdrl.default_reading_list_id = :parentDefaultListId " |
| 323 | "ORDER BY cdrl.ordering"); |
| 324 | selectQuery.bindValue(":parentDefaultListId", FAV_ID); |
| 325 | selectQuery.exec(); |
| 326 | |
| 327 | auto record = selectQuery.record(); |
| 328 | int id = record.indexOf("id"); |
| 329 | int fileName = record.indexOf("fileName"); |
| 330 | int title = record.indexOf("title"); |
| 331 | int currentPage = record.indexOf("currentPage"); |
| 332 | int numPages = record.indexOf("numPages"); |
| 333 | int hash = record.indexOf("hash"); |
| 334 | int read = record.indexOf("read"); |
| 335 | int coverSizeRatio = record.indexOf("coverSizeRatio"); |
| 336 | int number = record.indexOf("number"); |
| 337 | |
| 338 | while (selectQuery.next()) { |
| 339 | ComicDB comic; |
| 340 | |
| 341 | comic.id = selectQuery.value(id).toULongLong(); |
| 342 | comic.parentId = FAV_ID; |
| 343 | comic.name = selectQuery.value(fileName).toString(); |
| 344 | comic.info.title = selectQuery.value(title).toString(); |
| 345 | comic.info.currentPage = selectQuery.value(currentPage).toInt(); |
| 346 | comic.info.numPages = selectQuery.value(numPages).toInt(); |
| 347 | comic.info.hash = selectQuery.value(hash).toString(); |
| 348 | comic.info.read = selectQuery.value(read).toBool(); |
| 349 | comic.info.coverSizeRatio = selectQuery.value(coverSizeRatio).toFloat(); |
| 350 | comic.info.number = selectQuery.value(number); |
| 351 | |
| 352 | list.append(comic); |
| 353 | } |
| 354 | |
| 355 | connectionName = db.connectionName(); |
| 356 | } |
| 357 | // TODO ? |
| 358 | QSqlDatabase::removeDatabase(connectionName); |
| 359 | |
| 360 | return list; |
| 361 | } |
| 362 | |
| 363 | QList<ComicDB> DBHelper::getReading(qulonglong libraryId) |
| 364 | { |