]> Some of my projects - localmylist.git/commitdiff
Rework logic a bit, fix silly bug in getFile
authorAPTX <marek321@gmail.com>
Mon, 23 Jul 2012 15:51:06 +0000 (17:51 +0200)
committerAPTX <marek321@gmail.com>
Mon, 23 Jul 2012 15:51:06 +0000 (17:51 +0200)
localmylist/database.cpp

index 14411009ed02182c61ece7d4b1178cb80eb00115..5ebfd90f8e5b12cdf34990c44f0ad97ae7a4f4cf 100644 (file)
@@ -532,13 +532,8 @@ Episode Database::getEpisode(int eid)
        if (!exec(q))
                return e;
 
-       if (!q.next())
-       {
-               q.finish();
-               return e;
-       }
-
-       e = readEpisode(q);
+       if (q.next())
+               e = readEpisode(q);
 
        q.finish();
 
@@ -563,13 +558,9 @@ File Database::getFile(int fid)
        if (!exec(q))
                return f;
 
-       if (!q.next())
-       {
-               q.finish();
-               return f;
-       }
+       if (q.next())
+               f = readFile(q);
 
-       readFile(q);
        q.finish();
 
        return f;
@@ -577,6 +568,8 @@ File Database::getFile(int fid)
 
 File Database::getFileByPath(const QString &path)
 {
+       File f;
+
        QSqlQuery &q = prepare(
        "SELECT f.fid, f.eid, f.aid, f.gid, f.anidb_update, f.entry_update, f.my_update, "
        "               f.ed2k, f.size, f.length, f.extension, f.group_name, f.group_name_short, f.crc, "
@@ -591,13 +584,8 @@ File Database::getFileByPath(const QString &path)
        if (!exec(q))
                return File();
 
-       if (!q.next())
-       {
-               q.finish();
-               return File();
-       }
-
-       File f = readFile(q);
+       if (q.next())
+               f = readFile(q);
 
        q.finish();
 
@@ -606,6 +594,8 @@ File Database::getFileByPath(const QString &path)
 
 File Database::getFileByTitle(const QString &title, int epno)
 {
+       File f;
+
        QSqlQuery &q = prepare(
        "SELECT f.fid, f.eid, f.aid, f.gid, f.anidb_update, f.entry_update, f.my_update, "
        "               f.ed2k, f.size, f.length, f.extension, f.group_name, f.group_name_short, f.crc, "
@@ -640,15 +630,10 @@ File Database::getFileByTitle(const QString &title, int epno)
        q.bindValue(":epno", epno);
 
        if (!exec(q))
-               return File();
-
-       if (!q.next())
-       {
-               q.finish();
-               return File();
-       }
+               return f;
 
-       File f = readFile(q);
+       if (q.next())
+               f = readFile(q);
 
        q.finish();
 
@@ -932,6 +917,8 @@ bool Database::addUnknownFile(const UnknownFile &file)
 
 UnknownFile Database::getUnknownFile(const QByteArray &ed2k, qint64 size)
 {
+       UnknownFile f;
+
        QSqlQuery &q = prepare(
        "SELECT ed2k, size, host_id, path "
        "       FROM unknown_file "
@@ -942,14 +929,11 @@ UnknownFile Database::getUnknownFile(const QByteArray &ed2k, qint64 size)
        q.bindValue(":size", size);
 
        if (!exec(q))
-               return UnknownFile();
-
-       UnknownFile f;
+               return f;
 
        if (q.next())
-       {
                f = readUnknownFile(q);
-       }
+
        q.finish();
 
        return f;
@@ -957,6 +941,8 @@ UnknownFile Database::getUnknownFile(const QByteArray &ed2k, qint64 size)
 
 UnknownFile Database::getUnknownFileByPath(const QString &path)
 {
+       UnknownFile f;
+
        QSqlQuery &q = prepare(
        "SELECT ed2k, size, host_id, path "
        "       FROM unknown_file "
@@ -965,14 +951,11 @@ UnknownFile Database::getUnknownFileByPath(const QString &path)
        q.bindValue(":path", path);
 
        if (!exec(q))
-               return UnknownFile();
-
-       UnknownFile f;
+               return f;
 
        if (q.next())
-       {
                f = readUnknownFile(q);
-       }
+
        q.finish();
 
        return f;