From 5d92c3aa4f37aa1c43978ed155308d7e30c21305 Mon Sep 17 00:00:00 2001 From: APTX Date: Thu, 14 Jun 2012 18:53:13 +0200 Subject: [PATCH] Add a simple getFileByPath --- localmylist/database.cpp | 16 ++++++++++++++++ localmylist/database.h | 1 + 2 files changed, 17 insertions(+) diff --git a/localmylist/database.cpp b/localmylist/database.cpp index 00ee4a3..30c2a49 100644 --- a/localmylist/database.cpp +++ b/localmylist/database.cpp @@ -436,6 +436,22 @@ File Database::getFile(int fid) return f; } +File Database::getFileByPath(const QString &path) +{ + QSqlQuery q(d->db); + q.prepare("SELECT fid from file_location WHERE path = :path"); + q.bindValue(":path", path); + + if (!exec(q)) + return File(); + + if (!q.next()) + return File(); + + int fid = q.value(0).toInt(); + return getFile(fid); +} + bool Database::setAnime(const Anime &anime) { d->setAnimeQuery.bindValue(":aid", anime.aid); diff --git a/localmylist/database.h b/localmylist/database.h index e10d9db..02e17da 100644 --- a/localmylist/database.h +++ b/localmylist/database.h @@ -232,6 +232,7 @@ public: Anime getAnime(int aid); Episode getEpisode(int eid); File getFile(int fid); + File getFileByPath(const QString &path); bool setAnime(const Anime &anime); bool setEpisode(const Episode &episode); -- 2.52.0