]> Some of my projects - localmylist.git/commitdiff
Add a simple getFileByPath
authorAPTX <redacted>
Thu, 14 Jun 2012 16:53:13 +0000 (18:53 +0200)
committerAPTX <redacted>
Thu, 14 Jun 2012 16:53:13 +0000 (18:53 +0200)
localmylist/database.cpp
localmylist/database.h

index 00ee4a3..30c2a49 100644 (file)
@@ -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);
index e10d9db..02e17da 100644 (file)
@@ -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);