| 361 | } |
| 362 | |
| 363 | QList<ComicDB> DBHelper::getReading(qulonglong libraryId) |
| 364 | { |
| 365 | QString libraryPath = DBHelper::getLibraries().getPath(libraryId); |
| 366 | QList<ComicDB> list; |
| 367 | QString connectionName = ""; |
| 368 | |
| 369 | { |
| 370 | QSqlDatabase db = DataBaseManagement::loadDatabase(LibraryPaths::libraryDataPath(libraryPath)); |
| 371 | QSqlQuery selectQuery(db); |
| 372 | selectQuery.prepare("SELECT c.id,c.parentId,c.fileName,ci.title,ci.currentPage,ci.numPages,ci.hash,ci.read,ci.coverSizeRatio,ci.number " |
| 373 | "FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) " |
| 374 | "WHERE ci.hasBeenOpened = 1 AND ci.read = 0 " |
| 375 | "ORDER BY ci.lastTimeOpened DESC"); |
| 376 | selectQuery.exec(); |
| 377 | |
| 378 | auto record = selectQuery.record(); |
| 379 | int id = record.indexOf("id"); |
| 380 | int parentId = record.indexOf("parentId"); |
| 381 | int fileName = record.indexOf("fileName"); |
| 382 | int title = record.indexOf("title"); |
| 383 | int currentPage = record.indexOf("currentPage"); |
| 384 | int numPages = record.indexOf("numPages"); |
| 385 | int hash = record.indexOf("hash"); |
| 386 | int read = record.indexOf("read"); |
| 387 | int coverSizeRatio = record.indexOf("coverSizeRatio"); |
| 388 | int number = record.indexOf("number"); |
| 389 | |
| 390 | while (selectQuery.next()) { |
| 391 | ComicDB comic; |
| 392 | |
| 393 | // TODO: use QVariant when possible to keep nulls |
| 394 | comic.id = selectQuery.value(id).toULongLong(); |
| 395 | comic.parentId = selectQuery.value(parentId).toULongLong(); |
| 396 | comic.name = selectQuery.value(fileName).toString(); |
| 397 | comic.info.title = selectQuery.value(title).toString(); |
| 398 | comic.info.currentPage = selectQuery.value(currentPage).toInt(); |
| 399 | comic.info.numPages = selectQuery.value(numPages).toInt(); |
| 400 | comic.info.hash = selectQuery.value(hash).toString(); |
| 401 | comic.info.read = selectQuery.value(read).toBool(); |
| 402 | comic.info.coverSizeRatio = selectQuery.value(coverSizeRatio).toFloat(); |
| 403 | comic.info.number = selectQuery.value(number); |
| 404 | |
| 405 | list.append(comic); |
| 406 | } |
| 407 | connectionName = db.connectionName(); |
| 408 | } |
| 409 | // TODO ? |
| 410 | QSqlDatabase::removeDatabase(connectionName); |
| 411 | |
| 412 | return list; |
| 413 | } |
| 414 | |
| 415 | QList<ReadingList> DBHelper::getReadingLists(qulonglong libraryId) |
| 416 | { |